学习导图(图片在网上下载)

知识点详解(演示效果方便组件没有设置id)

(1)gravity和Layout_gravity

android:gravity 属性是对该view中内容的限定.比如一个button 上面的text. 你可以设置该text 相对于view的靠左,靠右等位置.

android:layout_gravity是用来设置该view相对与父view 的位置.比如一个button 在linearlayout里,你想把该button放在linearlayout里靠左、靠右等位置就可以通过该属性设置.

(2)weight权重(以水平为例)

  (a)当width = 0或者 width   = wrap_content的时候,按照权重比例计算!:2: 3

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_red_dark"
android:text="Text1"/>
<TextView
android:id="@+id/text2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@android:color/holo_blue_bright"
android:text="Text2"/>
<TextView
android:id="@+id/text3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_weight="3"
android:text="Text3"/>
</LinearLayout>

  (b)当width = fill_parent/match_parent的时候

    第一步:当三个都为match_parent的时候屏幕只有一个 1 -3 = -2;

    第二步:计算每个TextView占有的比例 1/6,2/6,3/6;

    第三步: 1 -2*1/6 = 2/3;  1 - 2*2/6 = 1/3; 1 - 2*3/6 = 0;

    第四步:2:1:0

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_red_dark"
android:text="Text1"
android:gravity="center"
android:textSize="40sp"/>
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@android:color/holo_blue_bright"
android:text="Text2"
android:gravity="center"
android:textSize="40sp"/>
<TextView
android:id="@+id/text3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_weight="3"
android:text="Text3"
android:gravity="center"
android:textSize="40sp"/>
</LinearLayout>

(3)分割线

 <View
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_width="3"
android:layout_height="match_parent"
android:background="#ff00ee" />

案例(底部导航)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
> <LinearLayout
android:layout_width="match_parent"
android:layout_height="80sp"
android:layout_gravity="bottom"
android:background="@android:color/holo_purple">
<LinearLayout
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_width="3"
android:layout_height="match_parent"
android:background="#ff00ee" />
<LinearLayout
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_width="3"
android:layout_height="match_parent"
android:background="#ff00ee" />
<LinearLayout
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three"
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

android的布局-----LinearLayout(线性布局)的更多相关文章

  1. android 59 LinearLayout 线性布局

    ##常见的布局* LinearLayout 线性布局线性布局往左右拉是拉不动的,> 线性布局的朝向 vertical|horizontal> 线性布局的权重 weight 和 0dip一起 ...

  2. Android布局管理详解(1)—— LinearLayout 线性布局

    Android的布局方式共有6种,分别是LinearLayout(线性布局).TableLayout(表格布局).FrameLayout(帧布局).RelativeLayout(相对布局).GridL ...

  3. Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件

    UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...

  4. Android零基础入门第25节:最简单最常用的LinearLayout线性布局

    原文:Android零基础入门第25节:最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认 ...

  5. Android基础_2 Activity线性布局和表格布局

    在activity的布局中,线性布局和表格布局是最简单的,这次分别从线性布局,表格布局以及线性布局和表格混合布局做了实验,实验中只需要编写 相应的xml的代码,java代码不需要更改,因为我们这里只是 ...

  6. android布局之线性布局

    LinearLayout 线性布局有两种,分别是水平线性布局和垂直线性布局,LinearLayout属性中android:orientation为设置线性布局当其="vertical&quo ...

  7. 2.2.1 LinearLayout(线性布局)

    本节引言 本节开始讲Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局), RelativeLayout(相对布局), TableLayout(表格布局) ...

  8. 第21/22讲 UI_布局 之 线性布局

    第21/22讲 UI_布局 之 线性布局 布局管理就是组件在activity中呈现方式,包括组件的大小,间距和对齐方式等. Android提供了两种布局的实现方式: 1.在xml配置文件中声明:这种方 ...

  9. Android:控件布局(线性布局)LinearLayout

    LinearLayout是线性布局控件:要么横向排布,要么竖向排布 决定性属性:必须有的! android:orientation:vertical (垂直方向) .horizontal(水平方向) ...

随机推荐

  1. mysql零散操作

    添加对外用户 CREATE USER 'admin'@'%' IDENTIFIED BY '!QAZ2wsx'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%'; ...

  2. 刷表法动态规划:HOJ11391_Word Clouds Revisited

    题目大意,给若干方块,让把方块拍成若干行,使得最终高度最小.其中,每行有宽度限制,高度为每行中最高的箱子的高度. 于是,很直观的认为,这个题可能也许大概应该是个动态规划的题. 于是,设DP[K]为K及 ...

  3. mysql--timestamp加减

    利用timestamp()对timestamp类型进行秒加减操作: 1.加10秒: 2.减10秒:

  4. D3DXCreateTexture

    HRESULT D3DXCreateTexture( __in LPDIRECT3DDEVICE9 pDevice, __in UINT Width, __in UINT Height, __in U ...

  5. SVM python小样例

    SVM有很多种实现,但是本章只关注其中最流行的一种实现,即序列最小化(SMO)算法在此之后,我们将介绍如何使用一种称为核函数的方式将SVM扩展到更多的数据集上基于最大间隔的分割数据优点:泛化错误率低, ...

  6. C语言编程题001

    有一颗树,一年两个生长周期,春天它长高一倍,夏天长高1m,问N个周期后树有多高?假设从春天开始树高为1m,第0个周期树高为1m. 要求:1.可以同时输入多个生长周期 如:3//表示下面有几个生长周期 ...

  7. Mac进行一些操作时提醒Operation not permitted的完美解决

    Mac版本10.14.5 ,向下向上都行: 1.关闭mac的安全机制,首先可以在正常模式下,输入 csrutil status 命令,查看mac安全机制是否开启. 2.如果 Protection st ...

  8. Postgres 将查询结果同时插入数据表

    INSERT INTO table [ ( column [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ... ...

  9. Python 拓展之迭代器

    写在之前 今天来讲讲「迭代器」的内容,其实已经拖了好多天了,感觉再不写就要忘记了.「迭代」相信对你来说已经不陌生了,我前面曾经专门用一篇文章来讲,如果你已经没有什么印象的话,就再点进去看看(零基础学习 ...

  10. Python面向对象之什么是类(1)

    1.C#.Java :只能用面向对象编程 Ruby.Python :函数编程+ 面向对象 面向对象编程不是在所有地方都比函数式编程方便的,类是为了封装,下面是简单的使用方法 在创建类的时候要用clas ...