Reputation: 31
I have a background image in full screen with a RelativeLayout
. And other image (100x100) in an ImageView
.
I want to put the ImageView
in center screen. But my image shows top left.
What is the problem?
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondo_inicio" >
<ImageView android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:gravity="center"
android:background="@drawable/icono_inicio"/>
</RelativeLayout>
Upvotes: 0
Views: 10950
Reputation: 617
User layout_gravity
and gravity
doesn't work in case of RelativeLayout
so just use
Layout_centerInParent = "true"
Upvotes: 0
Reputation: 1869
<ImageView
android:id="@+id/pic_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/pic" />
Upvotes: 0
Reputation: 11556
Add the following to the ImageView.
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
Upvotes: 2
Reputation: 5145
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fondo_inicio" >
<ImageView android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:background="@drawable/icono_inicio"/>
</RelativeLayout>
Upvotes: 0