我有高度和宽度为 match_parent 的 Imageview。我需要水平居中的图像不将宽度更改为 wrap_content。您可以更改父布局。
这是我的 xml。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="matrix"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
最佳答案
<ImageView android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
这应该适合您的需要,如果您需要更多信息,请查看:scaletype description
试试下面的代码:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
关于android - Imageview 宽度 match_parent 需要水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27395259/