LinearLayout ,它的理解很简单:在LinearLayout 里面的控件,以垂直或水平的方向,按照相对位置来排列所有的控件(包括所有的widgets 和containers)。如果LinearLayout设置成为垂直,那么每一行只会有一个widget或者是container,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高子控件的高度加上边框高度)。
一个简单的例子:
<?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:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
/>
</LinearLayout>
效果图如下:
在上个例子中,两个TextView 会按照垂直方向排列。
参数解释:
android:orientation 决定了排列方向, 如果参数orientation="horizontal" 则按照水平排列;如果参数orientation=" vertical" ,则按照垂直排列 。
android:layout_width,定义当前视图在屏幕上可以占据的宽度,fill_parent即填充整个屏幕; wrap_content用当前视图的最佳宽度显示。
android:layout_height 定义当前视图在屏幕上可以占据的高度,和layout_width 类似。
当然LinearLayout,还有其他重要参数,将会在下一篇介绍。
- 大小: 4.9 KB
分享到:
相关推荐
为什么有时候像android:layout_marginBottom等变量的赋值为负数? 例如如下代码: <LinearLayout android:orientation="vertical" android:id="@id/Widget_2X4_frame" android:layout_width="fill_parent" ...
Android开源代码,自定义Layout,继承自LinearLayout,内部控件自动换行显示。例如:可用来开发数量变化的属性标签群。
www.mars-droid.com/Android开发视频教程 LinearLayout代码 源码 mars老师讲课 android 视频源码 Layout_01(在此特别感谢mars的无私奉献,此代码为跟随视频边学边做的)
Android中使用LinearLayout完成的四书五经首界面的代码清单 .pdf 学习资料 复习资料 教学资源
www.mars-droid.com/Android开发视频教程 LinearLayout TableLayout代码 源码 mars老师讲课 android 视频源码 Layout_04(在此特别感谢mars的无私奉献,此代码为跟随视频边学边做的)
Android Layout多种使用方法源码演示,这个例子中演示了如何使用FrameLayout、如何使用RelativeLayout、如何使用RelativeLayout和LinearLayout以及如何使用TableLayout的例子,都挺实用,平时用的比较多,但是比较...
Android开发学习23】界面布局之线性布局LinearLayout代码
-<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...
LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:id=”@+id/LinearLayout” android:layout_width=”fill_parent” android...
在做android UI布局时,用了LinearLayout嵌套,发现效果并不如我预料一般 查了下资料,说是要设置layout_weight属性 资料说得不是很清楚,也没仔细看,就去弄,结果越弄越混乱。 于是静下心来,自己写xml测试,发现...
LinearLayout是线性布局控件:要么横向排布,要么竖...(1)gravity和Layout_gravity android:gravity 属性是对该view中内容的限定.比如一个button 上面的text. 你可以设置该text 相对于view的靠左,靠右等位置. a
-<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...
代码如下:<...LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_p
NULL 博文链接:https://hanllove001.iteye.com/blog/1185205
首先说的是LinearLayout布局下的居中一般是这样的: ...<LinearLayout android:layout_width=fill_parent android:layout_height=fill_parent android:gravity=center|center_horizontal|center_vertical> //
<LinearLayout android:layout_width="fill_parent" android:gravity="center_horizontal" android:id="@+id/buttons" android:layout_below="@id/msg" android:padding="5dip" android:layout_height="wrap_...
自定义自动换行LinearLayout LayoutParams使用android.widget.LinearLayout.LayoutParams
本文实例介绍了Android中LinearLayout、AbsoluteLayout的用法,希望能对于初学Android的朋友起到一点帮助作用。具体内容如下: Android 的UI 布局都以Layout 作为容器,并且在上面按照规定排列控件,这方面跟JAVA 的...
LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列(通过android:orientation属性来控制),按照相对位置来排列所有的widgets或者其他的containers,超过边界时,某些控件将缺失或消失 ...
android:layout_width="fill_parent" android:layout_height="fill_parent" > android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> android:id=...