tags:

views:

31

answers:

1

Hi,

How can I center ImageButton in the this LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main"
>

ImageButton

              <ImageButton android:id="@+id/btnBut"
                      android:background="@drawable/button"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content" />

I don't want to use fixed sizes.

Thanks

+1  A: 

Use android:layout_gravity attribute:

 <ImageButton android:id="@+id/btnBut"
    android:background="@drawable/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />
Konstantin Burov
@Konstantin Burov, I try with this but ImageButton center only horizontal, I want to be in center of screen. Can you help me ? Thanks
Jovan
Can you post the whole layout then?
Konstantin Burov
I fixed this with RelativeLayout and android:layout_centerInParent="true"
Jovan