简体   繁体   中英

How can I set the imageview to take up the width of the screen?

I would like an imagview that takes up the width of the screen (or layout) but there seems to be padding around the view that prevents me from doing this.

在此处输入图片说明

With the corresponding xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<ImageView android:src="@drawable/icon" android:background="@null"
    android:layout_height="106dp" android:id="@+id/imageView1"
    android:layout_weight="0.59" android:layout_width="match_parent"></ImageView>

</LinearLayout>

The padding is come from transparent area on android icon. Just remove unused transparent area or use another image.

Try changing:

android:layout_width="match_parent"

to:

android:layout_width="fill_parent"

make layout width and height as fill_parent

<ImageView android:src="@drawable/icon" android:background="@null"
android:layout_height="fill_parent" android:id="@+id/imageView1"
android:layout_weight="1" android:layout_width="fill_parent"></ImageView>

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