2014-12-24 42 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" /> 
相关问题