LinearLayout 线性布局
LinearLayout 按照垂直或者水平的顺序依次排列子元素,每一个子元素位于前一个元素之后。
LinearLayout 中的子元素属性:android:layout_weight生效,它用于描述该子元素在剩余空间中占有的大小比例,加入一行只有一个文本框,那么它的默认值就是0,如果一行中有两个等长的文本框,那么他们的android:layout_weight值可以同为:1,如果一行中有两个不等长的文本框,那么他们的android:layout_weight值分别为:1和2 ,那么第一个文本框将占据剩余空间的三分之二,第二个文本框将占剩余空间的三分之一,android:layout_weight遵循数值越小,重要度越高的原则;
效果图:
<!--
布局之一:线性布局 LinearLayout
横向布局:一行多列 纵向布局:一列多行
LinearLayout的属性:
android:background 设置整个布局画面的背景
android:orientation="horizontal" 子元素的排列队形,是横向排列还是纵向排列
android:gravity="bottom" 子元素在布局中的缺省(默认)对齐方式
android:padding 设置子元素的彼次连接,中间不留空白
子元素的属性:
android:layout_gravity 设置自身对象在父布局中的看齐方式,可以更新父布局对象给定的缺省的值
android:layout_weight 将父布局中剩余的尺寸按各兄弟元素的weight值比例进行填充;
-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
- 大小: 4.1 KB
分享到:
相关推荐
AndroidStdio LinearLayout 线性布局写一个登录界面_顾缘君兮的博客-CSDN博客.html
主要为大家详细介绍了AndroidUI组件LinearLayout线性布局,具有一定的实用性,感兴趣的小伙伴们可以参考一下
LinearLayout是线性布局控件:要么横向排布,要么竖向排布,下面通过本篇文章给大家介绍Android布局之LinearLayout线性布局,涉及到android linearlayout 布局相关知识,对本文感兴趣的朋友一起学习吧
主要给大家介绍了关于Android自定义LinearLayout但布局显示不完整的解决方法,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
用Android Studio 2.3.3做的线性布局例子,主要用到的标签有:<LinearLayout></LinearLayout>;主要用到的设置有:android:orientation="horizontal"、android:layout_weight="1"。
很多时候,线性布局需要嵌套其他布局,比如线性布局,相对布局等
Android开发学习23】界面布局之线性布局LinearLayout代码
线性布局(LinearLayout)是 Android 中最基本的布局之一,用于在界面上按照水平或垂直方向依次排列子视图。它是一种简单而灵活的布局方式,适用于许多应用场景,如列表项、工具栏、表单等等。 在 Android 开发中,...
主要介绍了Android编程之线性布局LinearLayout用法,结合实例形式简单分析了Android线性布局的使用技巧,需要的朋友可以参考下
摘要:Java源码,Android源码,线性布局 一个基础级的Android线性布局实例——LinearLayout源码下载,帮助Android初学者了解线性布局的思路和实现方法,这里暂时没有安卓运行环境,所以没有抓到运行效果,还望理解,...
Android移动应用开发线性布局LinearLayout的常用属性.pdf 学习资料 复习资料 教学资源
Android移动应用开发线性布局LinearLayout的weight属性简介.pdf 学习资料 复习资料 教学资源
Android常见的布局类型是线性布局(LinearLayout),包含布局方向设置、基本使用、常用使用案例以及实现均分案例(垂直均分、水平均分)、以及线性布局嵌套,实现垂直且水平居中,整体按照“理论+案例”,分析清晰,...
android 线性布局LinearLayout实例代码,需要的朋友可以参考一下
线性布局(LinearLayout):按照垂直或者水平方向布局的组件。 帧布局(FrameLayout):组件从屏幕左上方布局组件。 表格布局(TableLayout):按照行列方式布局组件。 相对布局(RelativeLayout):相对其它组件的...
但是从面向对象的观点来看,ViewGroup 继承自 View,所以 ViewGroup组件布局——线性布局LinearLayout 是线性布局控件,它包含的子
LinearLayout 线性布局 控制组件 横向 或者 纵向 排列 RelativeLayout 相对布局 子组件的位置总是相对兄弟组件,父容器来决定的 FrameLayout 帧布局、框架布局 创建一个空白区域, 一个区域成为一帧 TableLayout 表格...
主要介绍了Android App中的多个LinearLayout嵌套布局实例,利用线性布局来排列按钮是安卓应用布局中的常用做法,需要的朋友可以参考下