I try to arrange two buttons (with images on them which work fine) next to each other and to center them horizontally. That's what I have so far:
<LinearLayout android:orientation="horizontal" android:layout_below="@id/radioGroup"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center">
<Button
android:id="@+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/radioGroup"
android:layout_gravity="center_horizontal"
android:drawableLeft="@drawable/accept_btn"
android:text="Allow"/>
<Button
android:id="@+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/allow"
android:layout_below="@id/radioGroup"
android:layout_gravity="center_horizontal"
android:drawableLeft="@drawable/block_btn"
android:text="Deny"/>
</LinearLayout>
Unfortunately they are still aligned to the left side. Any help is appreciated! Yves
Edit:
Unfortunately none of the comments or suggestions work so far. That's why I try to provide a simplified, full layout now with a RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button
android:id="@+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/TextView01"
android:text="Allow"/>
<Button
android:id="@+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/allow"
android:layout_alignTop="@id/allow"
android:text="Deny"/>
</RelativeLayout>
I've tried all combinations of attributes in the LinearLayout and on the Button elements without luck. Any other ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…