[转]RelativeLayout(Android)中实现控件平分屏幕

原文

在Android中,使用LinearLayout布局要实现控件平分屏幕很简单,直接使用它的layout_weight属性即可实现。

但是在RelativeLayout布局中却没有提供类似的属性。
在网上查了一会,发现一老外提供了他的方法,想法挺好~下面提供这种方法来实现平分的功能:

 

<RelativeLayout
   
android:layout_width="fill_parent"
   
android:layout_height="wrap_content">
   
<Viewandroid:id="@+id/strut"
       
android:layout_width="0dp"
       
android:layout_height="0dp"
       
android:layout_centerHorizontal="true"/>
   
<Button
       
android:layout_width="0dp"
       
android:layout_height="wrap_content"
       
android:layout_alignRight="@id/strut"
       
android:layout_alignParentLeft="true"
       
android:text="Left"/>
   
<Button
       
android:layout_width="0dp"
       
android:layout_height="wrap_content"
       
android:layout_alignLeft="@id/strut"
       
android:layout_alignParentRight="true"
       
android:text="Right"/>
</RelativeLayout>
看看就懂了,不多解释。
 
参考:
posted @ 2013-06-02 14:55  fzyzcjy  阅读(380)  评论(0)    收藏  举报