user1424394
user1424394

Reputation: 116

Positioning the logo to center in android

I am using this code for the image:

<ImageView android:src="@drawable/logo"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginLeft="50dip"/>

I want the logo to be centered , it can be done by varying the Layout margin left value and check and position it, but is there any command to get it centered?

Upvotes: 0

Views: 156

Answers (4)

Azulflame
Azulflame

Reputation: 1542

even better: use an image file the size of the screen (even fi it has balck space around it)

Upvotes: 0

ninge
ninge

Reputation: 1598

You could also use the element android:layout_centerInParent to center the image in the parent (container)

Upvotes: 0

John Boker
John Boker

Reputation: 83699

depending on the other part of your layout you could use a set the gravity of it's parent to center_vertical|center_horizontal.

Upvotes: 0

Simon Dorociak
Simon Dorociak

Reputation: 33495

Try to use RelativeLayout:

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView 
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/app_logo"
        android:contentDescription="application_logo"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        />

</RelativeLayout>

If you want to use only horizonal alignment, only remove android:layout_centerVertical="true" from XML resource.

Upvotes: 1

Related Questions