2014-12-24 71 views

回答

1

嘗試使用的LinearLayout封裝的按鈕,這樣的:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" 
    android:id="@+id/main"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button1" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button2" /> 
    </LinearLayout> 

</FrameLayout> 
0

您可以使用layout_gravity屬性:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

     <Button 
      android:layout_gravity="left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="button 1" 
      android:id="@+id/button_1" /> 

     <Button 
      android:layout_gravity="right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="button 2" 
      android:id="@+id/button_2" /> 

</FrameLayout> 

值重力可以組合,如:left|topleft|center_verticalleft|bottom , 等等。

你也可以使用左邊距值的第二個按鈕,例如:

 <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="200dp" 
      android:text="button 2" 
      android:id="@+id/button_2" /> 

...或者,爲什麼不利用重力和保證金的權利,以放置按鈕數量DP的從右邊距

 <Button 
      android:layout_gravity="right" 
      android:layout_marginRight="200dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="button 2" 
      android:id="@+id/button_2" /> 
相關問題