Skizit Skizit - 7 months ago 61
Android Question

Android: Center an image

I've got a linear layout and an image...

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=""
android:orientation="vertical" android:layout_width="fill_parent"

<ImageView android:layout_width="wrap_content" android:id="@+id/imageView1"
android:src="@drawable/icon" android:layout_height="wrap_content"


How do I dynamically center my image so that it will appear in the center of the screen on all devices?


In LinearLayout, use: android:layout_gravity="center".

In RelativeLayout, use: android:layout_centerInParent="true".