2016-07-31 12 views
0

私はRelativeLayoutボタンを1つまたは2つ表示するために使用しています。 2つのボタンの場合は、左右に整列させる必要があります。一方のボタンの場合は、中央に配置する必要があります。 RelativeLayout、2つのボタンの左揃え、右揃え

<RelativeLayout> 
    <Button 
    android:id="@+id/action" 
    android:layout_alignParentLeft="true"/> 
    <Button 
    android:id="@+id/dismiss" 
    android:layout_alignParentRight="true"/> 
</RelativeLayout> 

は、私は1つのボタンのケースのために View.GONEに却下ボタンを変更しましたが、アクションボタンは、まだ左に揃え - それは中央揃えにする任意の非programmatical方法はありますか?

+0

あなたは完全なxmlを投稿できますか? –

答えて

1
<LinearLayout 
    android:orientation="horizontal"> 
    <Button 
    android:id="@+id/action" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 
    <Button 
    android:id="@+id/dismiss" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 
</LinearLayout> 
+0

ありがとうございます!私は幅wrap_contentを使用し、それはまた動作します –

関連する問題