IMAGEVIEW.SRC set the picture resource, the picture does not stretch, but has the void part

Source: Internet
Author: User

problem IMAGEVIEW.SRC set the picture resource, the picture does not stretch, but has the void part:

    <linearlayout
        android:id= "@+id/linearlayout1"
        android:layout_width= "Wrap_content"
        android: layout_height= "Wrap_content"
        android:orientation= "vertical" >

    <imageview
        android:layout_width = "Wrap_content"
        android:layout_height= "205DP"
        android:scaletype= "Centerinside"
        android:background = "@drawable/feature_guide_1" >
    </ImageView>
    </LinearLayout>




FIX: There is no gap in the following settings

    <linearlayout
        android:id= "@+id/linearlayout1"
        android:layout_width= "Match_parent"
        android: layout_height= "Wrap_content"
        android:orientation= "vertical" >

        <imageview
            android:layout_width = "Wrap_content"
            android:layout_height= "wrap_content"
            android:layout_gravity= "center"
            android: Adjustviewbounds= "true"
            android:scaletype= "Fitxy"
            android:src= "@drawable/feature_guide_0" >
        </ImageView>
    </LinearLayout>


The following is a reprint of the reference content:

Recently encountered a demand, the requirement is not aware of the picture width and height of the case, let the picture in the specified width, while highly adaptive, in the network to find a bit, there are many solutions, and then for their own application, chose a modified smaller scheme, and finally proved that the effect is pretty good, recorded here, Hope to help people with the same needs.

Okay, here we are.

First, you need to add android:adjustviewbounds= "true" to your ImageView layout

<imageview android:id= "@+id/test_image"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:scaletype= "Fitxy"
Android:adjustviewbounds= "true"
android:layout_gravity= "Center"
android:contentdescription= "@string/app_name"
android:src= "@drawable/ic_launcher"/>

Then, set the ImageView in the code. Maximum width and maximum height, because the Adjustviewbounds property only works if the maximum height and maximum width are set

int screenwidth = Getscreenwidth (this);
Viewgroup.layoutparams LP = Testimage.getlayoutparams ();
Lp.width = ScreenWidth;
Lp.height = layoutparams.wrap_content;
TESTIMAGE.SETLAYOUTPARAMS (LP);

Testimage.setmaxwidth (ScreenWidth);
Testimage.setmaxheight (ScreenWidth * 5); It can actually be based on demand, and I'm testing 5 times times the maximum width here.


OK, next, then the normal way to load the picture will get the expected effect, the students need to try, good luck.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.