android - ImageView 不能在 RelativeLayout 中居中

标签 android xml imageview fragment android-relativelayout

我已经尝试添加 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/

相关文章:

android - SQLite 是本地数据库吗?

java - 上传前文件上传进度跳到 100%

java - OutOfMemoryException - 使用 Glide 的最佳方式

java - Spring Jaxb2 : How to append batch data to XML file with no reading it to memory?

c# - Web API 返回 JSON 但不返回 Xml

android - 某些设备上的 ImageView 黑色背景

java - ImageView 上的 NullPointerException

javascript - android webview使用本地javascript文件加载远程html文件

xml - 保留 xml 编码 XSLT

ios - 试图翻转 UIImage View 但是当翻转回来时我收到一个 nil