zoukankan      html  css  js  c++  java
  • 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>
    

  • 相关阅读:
    Java实现One-way traffic(单向交通)
    Java实现One-way traffic(单向交通)
    Java实现One-way traffic(单向交通)
    Java实现One-way traffic(单向交通)
    C#调用Delphi Dll返回字符串的示例(使用Move才能拷贝字符串)
    Delphi实现菜单项上出现提示
    WebBrowser中获得脚本中的变量值
    比较两个文件是否相同(比较两个流是否相等)
    WebBrowser执行脚本和调用外部方法
    c#之函数创建和闭包
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7399477.html
Copyright © 2011-2022 走看看