2012-08-12 82 views
0

我有两个按钮一个保存到SD卡和其他共享它(图像) 我需要它们是相等的,各是到屏幕的一半..Android的布局 - 等距间隔的按钮

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/btnShare" 
     android:layout_height="50dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:text="Share" 
     android:textColor="#000000" 
     android:typeface="serif" 
     android:layout_width="wrap_content"  
     android:layout_alignParentLeft="true"/> 

    <Button 
     android:id="@+id/btnSD" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="Save to SD Card" 
     android:textColor="#000000" 
     android:typeface="serif" 
     android:layout_alignParentRight=""/> 

</RelativeLayout> 

atm份额超过保存到sd

回答

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/btnShare" 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:layout_weight=".5" 
     android:text="Share" 
     android:textColor="#000000" 
     android:typeface="serif" /> 


    <Button 
     android:id="@+id/btnSD" 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:layout_weight="0.50" 
     android:text="Save to SD Card" 
     android:textColor="#000000" 
     android:typeface="serif" /> 

</LinearLayout> 
+0

感谢的人,是工作=) – 2012-08-12 19:56:41

+1

你并不真的需要设置0.5为重。这些只是相对值。只需要为两者设置相同的值,并且正如thujeevan所指出的那样,即可将您希望均衡为0dp的角色设置为。 – 2012-08-12 20:16:23

3

您将需要使用layout_weight。这将允许您按比例定义按钮的大小,如果您愿意,可以使它们相等。请记住根据方向将layout_width或layout_height设置为0px。

您还需要更改为LinearLayout才能使用它。

+0

只知道x.x中,感谢=) – 2012-08-12 19:57:06