简体   繁体   中英

imageview not perfect in nexus 6 with android:layout_alignParentBottom=“true”

I have created custom image and I am setting it at the bottom of the layout :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/btn_1"/>
</RelativeLayout>

It works with smaller devices but not with nexus 6 and above: I have drawable-mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi with image size:

360*174
540*261
720*347
1080*521
1440*676

It has gap on left and right side in nexus 6 and nexus 7,9,10 are not re-sizing ? Is there anything like xxxxhdpi and xxxxxhdpi? How can I get it to work ? I really appreciate any help.

1) There's white space on both sides because image is smaller than phone's size.

You have to scale your image so it set's at the bottom without showing any empty space.

You can achieve this by setting scaleType here's one example of how you can use it.

2) You are setting width and height to wrap_content . It means it will reduce the ImageView size based on actual image size. If you want to fit all to your screen then set match_parent .

<ImageView 
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/btn_1"
        />

You can set some height otherwise it will take full screen.

If it doesn't work for you then you can try to change scaleType to desire value such as center , centerInside , fitCenter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM