LinearLayout线性布局,线性布局是所有布局中最常用的,它可以让其中的子元素垂直或水平的方式排列(通过排列方向的设置)。通常复杂的布局都是在LinearLayout布局中嵌套而成的。
下面看一个LinearLayout的例子,这个例子中有垂直和水平的嵌套使用,例子如下图7-12所示。
图7-12 LinearLayout
布局文件请参考代码清单7-14,完整代码请参考chapter7_2工程中linearlayout2.xml代码部分(chapter7_2/res/layout/linearlayout2.xml)。
【代码清单7-14】
<?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">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello"
android:textSize="20dip" android:gravity="center" />
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/user"
android:textSize="15dip" />
<EditText android:id="@+id/username" android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/pass"
android:textSize="15dip" />
<EditText android:id="@+id/password" android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button android:text="@string/loginbtn" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@string/registerbtn" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>
出自《Android开发案例驱动教程》第七章
- 大小: 14.4 KB
分享到:
相关推荐
关于linearlayout布局案例
主要为大家详细介绍了AndroidUI组件LinearLayout线性布局,具有一定的实用性,感兴趣的小伙伴们可以参考一下
Android 线性布局属性的详解,由于是Android Studio工程有点大。
详解android开发中的四大布布局的用法和注意点 LinearLayout,RelativeLayout,TableLayout,FrameLayout
Android应用开发
原需求,在一个伸缩列表中,自定义LinearLayout继承LinearLayout动态添加布局。 然而实现的时候:一共遍历了30条数据,却只显示了一条 断点查看代码:遍历addView()这个过程是正常的30次循环。那是布局的问题? ...
android LinearLayout 布局实例代码,需要的朋友可以参考一下
主要介绍了Android中LinearLayout布局的常用属性总结,包括居中、重心、比例等线性布局中的基本设置,需要的朋友可以参考下
LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列,按照相对位置来排列所有的widgets或者其他的containers,超过边界时,某些控件将缺失或消失
AndroidStdio LinearLayout 线性布局写一个登录界面_顾缘君兮的博客-CSDN博客.html
android 实现自动换行的布局,实现LinearLayout实现不了的换行
在做android UI布局时,用了LinearLayout嵌套,发现效果并不如我预料一般 查了下资料,说是要设置layout_weight属性 资料说得不是很清楚,也没仔细看,就去弄,结果越弄越混乱。 于是静下心来,自己写xml测试,发现...
LinearLayout是线性布局控件:要么横向排布,要么竖向排布,下面通过本篇文章给大家介绍Android布局之LinearLayout线性布局,涉及到android linearlayout 布局相关知识,对本文感兴趣的朋友一起学习吧
线性布局(LinearLayout):按照垂直或者水平方向布局的组件。 帧布局(FrameLayout):组件从屏幕左上方布局组件。 表格布局(TableLayout):按照行列方式布局组件。 相对布局(RelativeLayout):相对其它组件的...
android studio 初学者 Linearlayout 水平和垂直的布局文件
通过继承LinearLayout实现的自定义的布局,来实现简单的按钮界面
在一般情况下,当有很多控件需要在一个界面列出来时,我们就可以使用线性布局(LinearLayout)了,线性布局是按照垂直方向(vertical)或水平方向(horizontal)的顺序依次排序子元素,每一个子元素都位于前一个元素之后,下面...