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
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
If you have a single Button in your Activity and you want to center it the simplest way is to use a RelativeLayout and set the android:layout_centerInParent=”true” property on the Button.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With