1、按比例显示控件元素

    <EditText        android:id="@+id/edit_message"        android:layout_weight="2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:hint="@string/edit_message" >        <requestFocus />    </EditText>        <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_weight="1"        android:text="@string/button_send" />


属性weight的作用(不翻了,将就看吧):

if you give one view a weight of 2 and another one a weight of 1, the sum is 3, so the first view fills 2/3 of the remaining space and the second view fills the rest. If you add a third view and give it a weight of 1, then the first view (with weight of 2) now gets 1/2 the remaining space, while the remaining two each get 1/4.

EditText 占 2/3 , Button 占 1/3.

注意:只有当这两个控件的layout_width、layout_height都设置为"wrap_content"时,这个规则才能够成立。

2、一个控件独占,其它控件根据自身内容自动调整。

将需要独占的控件,其weight设置为1,同时宽度设置为0dp。根据自身内容调整的控件,不要设置weight。

效果:

更多相关文章

  1. Android(安卓)控件布局常用属性
  2. Android(安卓)控件布局常用属性
  3. Android属性
  4. Android(安卓)控件相关
  5. Android学习第一章第一节android学习路线图
  6. ANDROID 控件常用属性
  7. AndroidUI组件之ListView小技巧
  8. AndroidUI组件之ListView小技巧
  9. Android设置窗口、控件透明度

随机推荐

  1. Android提供的LruCache类简介
  2. Android使用ccache减少编译时间
  3. android 应用程序性能跟踪
  4. Android(安卓)uses-permission 总结
  5. Android发送Email
  6. android.databinding.tool.util.LoggedEr
  7. Android(安卓)监听Fragment界面的点击事
  8. video player demo in android
  9. Android版本检测\自动更新
  10. android——ListView功能的实现(使用simp