android 59 LinearLayout 线性布局

简介:

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

复制代码
<?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="vertical" >  垂直排列,里面的内容垂直排列

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dip"  高度为0,则高度根据权重来占比例,
        android:layout_weight="1"  权重为1,则高度为权重和的1份即1/3,权重只能跟为0的宽度或高度,
        android:text="按钮1" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:text="按钮2" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:text="按钮3" />

</LinearLayout>
复制代码
复制代码
<?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" >   水平排列,不用权重则多的将会挤出去,

    <Button
        android:layout_width="0dip"  宽度为0,
        android:layout_height="wrap_content"  高度填充父窗体,和父组件宽度一样宽,
        android:layout_weight="2"    权重为2,则宽度为权重和的2份即2/4,权重只能跟为0的宽度或高度,
        android:text="按钮1" />

    <Button
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"   权重为1,则宽度为权重和的1份
        android:text="按钮2" />

    <Button
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"        权重为1,则宽度为权重和的1份
        android:text="按钮3" />

</LinearLayout>
复制代码

 

 以上的代码:

复制代码
<?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="vertical" >   最外层是线性布局,垂直排列

    <LinearLayout
        android:orientation="horizontal"     里面是水平排列
        android:layout_width="match_parent"  宽度为父窗体宽度
        android:layout_weight="1"       权重为1
        android:layout_height="0dip" >  写0可以用权重了
        <TextView 
               android:layout_width="0dip"      宽度为0
        android:layout_height="fill_parent"     高度为父窗体
        android:layout_weight="1"              宽度权重为1
            android:background="#ff0000"
            />
        <TextView 
               android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="1"
            android:background="#00ff00"
            />
        <TextView 
               android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="1"
            android:background="#0000ff"
            />
        
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"     里面垂直排列
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dip" >
          <TextView 
               android:layout_width="fill_parent"   宽度为父窗体
        android:layout_height="0dip"        高度为0
        android:layout_weight="1"           高度权重为1
            android:background="#ff0000"
            />
        <TextView 
               android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
            android:background="#00ff00"
            />
        <TextView 
              android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
            android:background="#0000ff"
            />
        
        
    </LinearLayout>

</LinearLayout>
复制代码

 


本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/4915477.html,如需转载请自行联系原作者


相关文章
|
1月前
|
XML Android开发 数据格式
android点击FrameLayout、LinearLayout等父布局没响应的原因以及解决方案
android点击FrameLayout、LinearLayout等父布局没响应的原因以及解决方案
30 2
|
4月前
|
数据可视化 Android开发 容器
Android UI设计: 请解释LinearLayout、RelativeLayout和ConstraintLayout的区别。
Android UI设计: 请解释LinearLayout、RelativeLayout和ConstraintLayout的区别。
97 5
|
5月前
|
Android开发
Android Studio入门之常用布局的讲解以及实战(附源码 超详细必看)(包括线性布局、权重布局、相对布局、网格布局、滚动视图 )
Android Studio入门之常用布局的讲解以及实战(附源码 超详细必看)(包括线性布局、权重布局、相对布局、网格布局、滚动视图 )
146 0
|
26天前
|
XML 数据可视化 Java
Android布局——线性布局、相对布局、帧布局、表格布局、网格布局、约束布局
Android布局——线性布局、相对布局、帧布局、表格布局、网格布局、约束布局
|
5月前
|
Android开发 容器
Android开发,学习LinearLayout布局
Android开发,学习LinearLayout布局
43 0
|
9月前
|
XML Android开发 数据格式
Android XML 布局基础(五)线性布局 - LinearLayout
Android XML 布局基础(五)线性布局 - LinearLayout
86 0
|
12月前
|
Android开发 容器
Android 实现控件对称布局(约束布局和线性布局)
画界面时会遇到很多界面上的布局,虽然很简单,但是每次做起来不熟练,总结一下一些日常的
|
XML Android开发 数据格式
Android自定义控件(十一)——自定义ViewGroup实现LinearLayout
Android自定义控件(十一)——自定义ViewGroup实现LinearLayout
423 0
|
XML Android开发 数据格式
Android LinearLayout使用selector改变交互时背景颜色
 换言之,就像Android Button一样,基于布局文件,把LinearLayout做成一个可以在用户交互触摸点击时候背景颜色有所改变的控件。
1341 0
|
数据安全/隐私保护 Android开发
Android Studio 线性布局LinerLayout实例
本文目录 1. 简单线性布局 2. 嵌套线性布局
388 0
Android Studio 线性布局LinerLayout实例