tags:

views:

729

answers:

3

Hi All,

I want to put layout in center of the screen. Please help me here.

+3  A: 

You can apply a centering to any View, including a Layout, by using the XML attribute android:layout_gravity". You probably want to give it the value "center".

You can find a reference of possible values for this option here: http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr%5Fandroid%3Alayout%5Fgravity

Klondike
AFAIK, layout_gravity is only for LinearLayout, not for arbitrary layouts.
CommonsWare
As you mentioned layout_gravity is only for LinearLayout what about RelativeLayout because because in app i want to embedd textview on ImageView
Jitu
i tried it also with relativelayout and in my opinion it works
Nitromouse
+3  A: 

Step #1: Wrap whatever it is you want centered on the screen in a full-screen RelativeLayout.

Step #2: Give that RelativeLayout the android:layout_centerInParent="true" attribute.

Step #3: There is no step #3.

CommonsWare
A: 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center">
    <ProgressBar
        android:id="@+id/ProgressBar01"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_gravity="center"
        android:layout_height="wrap_content"></ProgressBar>
    <TextView
        android:layout_below="@id/ProgressBar01"
        android:text="@string/please_wait_authenticating"
        android:id="@+id/txtText"
        android:paddingTop="30px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>
</RelativeLayout>
Pentium10