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>
    

  • 相关阅读:
    css相关
    文章管理列表
    高性能MySQL基础篇
    mysql
    node.js开发实战
    React Hooks
    client-*,scroll-*,offset-*的区别
    将create-react-app从javascript迁移到typescript
    为Github项目添加Travis持续集成服务
    cookie储存
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7399477.html
Copyright © 2011-2022 走看看