Вопрос

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>
Это было полезно?

Решение

try this to your ImageView

android:layout_centerInParent="true"

Другие советы



Add the following to the ImageView.

android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
<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>
<ImageView
        android:id="@+id/pic_id"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitCenter"
        android:src="@drawable/pic" />

Try this

android:layout_gravity="center"

User layout_gravity and gravity doesn't work in case of RelativeLayout so just use

Layout_centerInParent = "true"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top