星空网 > 软件开发 > ASP.net

第7章(3) LinearLayout(线性布局)

分类:C#、Android、VS2015;

创建日期:2016-02-10

一、简介

LinearLayout将容器内的组件一个挨着一个地横向或纵向依次堆叠起来(不重叠)。该布局和WPF的StackPanel控件的功能非常相似,也是通过orientation属性设置排列的方向是纵向(vertical)还是纵向(horizontal)。

常用属性有:

android:layout_gravity:子元素在容器中的对齐方式。即:往哪一端偏沉(gravity:重力)。

android:orientation:控制子元素的排列方式(横向排列、纵向排列)

android:layout_weight:表示其子元素占用空间的分配权重,值越小权重越大。

例如:

<LinearLayout

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

注意:子元素的宽和高必须至少有一个设置为“fill_parent”线性布局才会起作用。

二、示例—Demo01LinearLayout

1、设计界面

第7章(3) LinearLayout(线性布局)

2、运行效果

第7章(3) LinearLayout(线性布局)

3、添加Demo01LinearLayout.a在layout文件夹下添加该文件。

<??><LinearLayout ="http://schemas.android.com/apk/res/android"  android:orientation="vertical"  android:layout_width="match_parent"  android:layout_height="match_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="第1行"    android:textSize="15pt"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_weight="1" />  <TextView    android:text="第2行"    android:textSize="15pt"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_weight="1" />  <TextView    android:text="第3行"    android:textSize="15pt"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_weight="1" />  <TextView    android:text="第4行"    android:textSize="15pt"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_weight="1" /> </LinearLayout></LinearLayout>

4、添加Demo01LinearLayout.cs文件

在SrcDemos文件夹下添加该文件。

using Android.App;using Android.OS;namespace ch07demos.SrcDemos{  [Activity(Label = "Demo01LinearLayout")]  public class Demo01LinearLayout : Activity  {    protected override void OnCreate(Bundle savedInstanceState)    {      base.OnCreate(savedInstanceState);      SetContentView(Resource.Layout.Demo01LinearLayout);    }  }}

运行观察效果。


原标题:第7章(3) LinearLayout(线性布局)

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

电池类货物:https://www.goluckyvip.com/tag/2163.html
Ivy Yao:https://www.goluckyvip.com/tag/21630.html
Ivy杨烁:https://www.goluckyvip.com/tag/21631.html
iwoca:https://www.goluckyvip.com/tag/21632.html
iWriter:https://www.goluckyvip.com/tag/21633.html
IXSPY:https://www.goluckyvip.com/tag/21634.html
桂林酒店销售多少钱 桂林旅游宾馆价格:https://www.vstour.cn/a/410227.html
十里银滩旅游攻略玩什么住哪里怎么去?:https://www.vstour.cn/a/410228.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流