• 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"
          />

  • 相关阅读:
    tensorflow学习笔记13
    Java——内部类
    Java——枚举
    Java——代码块
    Java——static
    Java——接口
    Java——final
    Java——权限修饰符
    Java——多态
    Java——抽象类
  • 原文地址:https://www.cnblogs.com/AndroidCSY/p/6681732.html
Copyright © 2020-2023  润新知