zoukankan      html  css  js  c++  java
  • Android基础TOP3:线性布局的特点,常用属性,及权重值

    线性布局是一种让视图水平或者垂直布排列的布局;

    常用属性:

    androuid:orientation :表示布局方向

    •  取值vertical表示垂直布局
    •  取值horizontal表示水平布局

    android:gravity 表示视图对齐方式

    • 内容包括 TOP,bottom,left,right,center_vertical,center_horizontal,center
    • 可以使用“|”分割填写多个值

    布局中的视图可以使用如下多个属性:

    android:layout_gravity 表示单个视图的对齐方式

    android:layout_weight 表示单个视图所在大小的比重

    • 当Layout_weight为0时候视图大小自身确定
    • 当layout_weight大于0时,视图在线性布局方向根据比重拉伸

    代码演示:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:orientation="horizontal" >
     6     <Button 
     7         android:layout_width="200dp"
     8         android:layout_height="100dp"
     9         android:text="adaflkjn"
    10         android:gravity="bottom|center_horizontal"/>
    11 
    12 </LinearLayout>

    android:gravity:是决定控件内元素在某个位置

    <Button 
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:text="adaflkjn"
            android:layout_gravity="center"/>

    android:layout_gravity是本元素在父元素里面显示的位置

    weight的应用

    <EditText 
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:hint="sdaf"/>
       <Button 
           android:layout_width="1dp"
           android:layout_height="wrap_content"
           android:layout_weight="0"
           android:text="klndgjl"
           />

     <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0"
          android:text="weight为0"
          android:background="#FFF0F5"
          />
      <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="weight为1"
           android:layout_weight="1"
          android:background="#800080"
          />
       <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="weight为4"
           android:layout_weight="4"
          android:background="#4B0082"
          />

  • 相关阅读:
    9.10 作业
    Day 03 作业
    Day02作业
    Day09 函数
    day08 简单习题
    Day04 python数据类型和词云的生成
    JAVA: 子类通过static块“覆盖”父类的成员变量风险
    JAVA: 子类“覆盖”父类的成员变量
    Java 访问控制权限
    Java数组类型转为集合类型
  • 原文地址:https://www.cnblogs.com/AndroidCSY/p/6681732.html
Copyright © 2011-2022 走看看