android学习笔记(8)linearlayout与android:layout_weight学习

一,linearlayout

线性布局,布局文件中设置多个linearlayout来达到整体线性布局的风格.
android:gravity="right"对齐方式,居右对齐,gravity是重心的意思
常用参数:center(居中),bottom(下),top(上),right(右),left(左)

二,android:layout_weight
给控件分配可权值,不分配默认为0
权值为0的控件按原来的方式给他布局;分配了权值的控件,在除去权值为0的控件之外的区域按权值布局,
例如:布局中有2个控件,一个android:layout_weight="2",另一个android:layout_weight="1"则整个屏幕内三分之二被第一个控件占据,剩下的三分之一被第二个控件占据.

例子:实现如图布局:


<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

<LinearLayout
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- 水平布局 -->
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
      <EditText
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#ff0000"
          android:layout_weight="1">
      </EditText>
            
      <EditText
          android:layout_width="match_parent"
          android:layout_height="match_parent"  
          android:layout_weight="1" 
          android:background="#00ff00" >                            
       </EditText>
       <EditText
          android:layout_width="match_parent"
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:background="#0000ff">                             
       </EditText>
    </LinearLayout>
        
    <!-- 垂直布局 -->
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_gravity="right">
       <EditText
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1" 
          android:background="#2F2F4F">                    
      </EditText>
      <EditText
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_weight="1" 
         android:background="#B87333">                    
      </EditText>
  </LinearLayout>
        
</LinearLayout>

</RelativeLayout>

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值