<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/wallpaper" />
</RelativeLayout>
@drawable/peetscoffee_wallpaper
的大小是 640x480,但不是水平居中。
我该如何解决这个问题?
最佳答案
尝试使用 android:gravity="center"
或 android:layout_gravity="center"
,而不是 centerHorizontal="true"
。
但是,我怀疑这对于大小设置为 wrap_content
的图像是否合理 - 您可能想要使用 android:scaleType
定义一些图像缩放方法(例如 fitCenter
) 并将其设置为 fill_parent
而不是 wrap_content
。 640x480
大于当前真实 Android 设备支持的 320x480
。或者只是缩小您正在使用的图像,这样设备就不必做这项工作。
关于android - ImageView的麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/799607/