Search code examples
androidxmlimageviewfragmentandroid-relativelayout

ImageView cannot be centered in a RelativeLayout


I've already tried adding layout_gravity, and gravity, and centerInParent.. but the image view still shows up at the left upper corner of the screen..Am I missing something?

<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"
        />
    ....

Solution

  • I have tested your layout. Your ImageView is already in center. Its correct.

    I think there is a problem in android:background="@drawable/sign" perhaps sign image is not displaying correctly or not found or not in drawable folder.

    Try to change different image and other image will be in center perfectly.