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

时间: 2024-08-24 06:29:30

Android基础TOP3:线性布局的特点,常用属性,及权重值的相关文章

android基础之LinearLayout布局

LinearLayout布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="matc

Android 自学之线性布局 LinearLayout

线性布局(LinearLayout),线性布局有点想AWT编程里面的FolwLayout,他们都会将容器里面的组件挨个的排列起来. 他们最大的区别在于:Android的线性布局不会换行:AWT里面的FolwLayout则会另起一行进行显示 LinearLayout支持常用XML属性及相关方法的说明 XML属性 相关方法 说明 android:gravity setGravity(int) 设置布局管理器内组件的对齐方式.该属性支持top,bottom,left,right--也可以同时制定多种对

Android基础TOP3:Activity的线性,相对,帧和表格布局的概括

线性布局 LinearLayout: <LinearLayout 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中LinearLayout线性布局

android:orientation="vertical"垂直线性布局,"horizontal"水平线性布局 android:gravity="top"(buttom.left.right.center_vertical.fill_vertical.center_horizontal.fill_horizontal.center.fill.clip_vertical.clip_horizontal)控制布局中控件的对齐方式.如果是没有子控件的控

android 59 LinearLayout 线性布局

##常见的布局* LinearLayout 线性布局线性布局往左右拉是拉不动的,> 线性布局的朝向 vertical|horizontal> 线性布局的权重 weight 和 0dip一起使用 <?xml version="1.0" encoding="utf-8"?> <!-- 线性布局控件自上而下整齐的排列 --> <LinearLayout xmlns:android="http://schemas.andr

android学习——LinearLayout线性布局

LinearLayout线性布局 LinearLayout是一种线型的布局方式.LinearLayout布局容器内的组件一个挨着一个地排列起来:不仅可以控制个组件横向排列,也可控制各组件纵向排列.通过orientation属性设置线性排列的方向是垂直(vertical)还是纵向(horizontal). 我们下面通过XML布局和Java代码布局两种方式分别举例: 一.XML方式布局 1.创建一个空白Activity 2.打开“res/layout/activity_main.xml”文件,修改成

.Net程序员玩转Android开发---(6)线性布局LinearLayout

             LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容只能水平或垂直排列,也就是在一条直线上. 通过控件的属性可以控制该控件内的控件的位置以及大小.下面是放置了3个treeview控件的效果图,此LinearLayout控件的属性为垂直排列. 下面我们通过该控件的几个属性来了解下控件的用法 1.

.Net程序猿玩转Android开发---(6)线性布局LinearLayout

?????????????? ????????????? LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就是在一条直线上. 通过控件的属性能够控制该控件内的控件的位置以及大小.以下是放置了3个treeview控件的效果图.此LinearLayout控件的属性为垂直排列. ???????? ?? 以下我们通过该控件的几个属性来了解下控件的使用方法 ??????? 1.Orientation属性 ?????

Android之Linearlayouy线性布局

写了个小例子xml代码如下: 1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="