我已经尝试添加 layout_gravity、gravity 和 centerInParent
。但是 ImageView 仍然显示在屏幕的左上角。我是不是遗漏了什么?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/noHistroySign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:background="@drawable/sign"
/>
....
最佳答案
我已经测试了你的布局。您的 ImageView
已经位于中心。这是正确的。
我认为 android:background="@drawable/sign"
中存在问题,可能标志图像未正确显示或未找到或不在 drawable 文件夹中。
尝试改变不同的图像,其他图像将完美居中。
关于android - ImageView 不能在 RelativeLayout 中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31701109/