原文地址:http://pcq019.blog.163.com/blog/static/12460232320122155651430/

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

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

<RelativeLayout    android:layout_width="fill_parent"   android:layout_height="wrap_content">   <View android: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>

看看就懂了,不多解释。
参考: http://stackoverflow.com/questions/4961355/percentage-width-in-a-relativelayout

更多相关文章

  1. android TextView EditTextView一些技巧使用 (视图代码布局)
  2. Android设置透明状态栏,仿ios状态栏
  3. Android中TextSwitcher的功能与用法
  4. Android布局管理器(贞布局)
  5. Android学习笔记(五)第一个Android(安卓)程序----Hello world
  6. 格局中@null的代码实现方式
  7. Android绘制流程窗口启动流程分析(中)
  8. android 状态栏一体化实现
  9. android内置包的说明

随机推荐

  1. Android(安卓)组件长宽比重设置总结
  2. 关于Android中xml布局文件之android 入门
  3. Android(安卓)Wear开发者预览配置过程
  4. android 电池(三):android电池系统
  5. android 异步处理
  6. 跟大家分享下Android布局文件layout.xml
  7. Android(安卓)跑马灯效果auto scroll tex
  8. coreApp="true";android:sharedUserId="an
  9. android中用Spannable在TextView中设置超
  10. Android(安卓)GIS +webservice