【Android】第7章(3)LinearLayout(线性布局)
分类:C#、Android、VS2015; 创建日期:2016-02-10 一、简介 LinearLayout将容器内的组件一个挨着一个地横向或纵向依次堆叠起来(不重叠)。该布局和WPF的StackPanel控件的功能非常相似,也是通过orientation属性设置排列的方向是纵向(vertical)还是纵向(ho
分类:C#、Android、VS2015;
创建日期:2016-02-10
一、简介
LinearLayout将容器内的组件一个挨着一个地横向或纵向依次堆叠起来(不重叠)。该布局和WPF的StackPanel控件的功能非常相似,也是通过orientation属性设置排列的方向是纵向(vertical)还是纵向(horizontal)。
常用属性有:
android:layout_gravity:子元素在容器中的对齐方式。即:往哪一端偏沉(gravity:重力)。
android:orientation:控制子元素的排列方式(横向排列、纵向排列)
android:layout_weight:表示其子元素占用空间的分配权重,值越小权重越大。
例如:
android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" 注意:子元素的宽和高必须至少有一个设置为“fill_parent”线性布局才会起作用。 1、设计界面 2、运行效果 3、添加Demo01LinearLayout.axml文件 在layout文件夹下添加该文件。 4、添加Demo01LinearLayout.cs文件 在SrcDemos文件夹下添加该文件。 运行观察效果。二、示例—Demo01LinearLayout
<span style="color: #0000ff;"></span><span style="color: #ff00ff;">xml version="1.0" encoding="utf-8"</span><span style="color: #0000ff;">?></span>
<span style="color: #0000ff;"><span style="color: #800000;">LinearLayout </span><span style="color: #ff0000;">xmlns:android</span><span style="color: #0000ff;">="http://schemas.android.com/apk/res/android"</span><span style="color: #ff0000;">
android:orientation</span><span style="color: #0000ff;">="vertical"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="match_parent"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="match_parent"</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"><span style="color: #800000;">LinearLayout
</span><span style="color: #ff0000;">android:orientation</span><span style="color: #0000ff;">="horizontal"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="red"</span><span style="color: #ff0000;">
android:gravity</span><span style="color: #0000ff;">="center_horizontal"</span><span style="color: #ff0000;">
android:background</span><span style="color: #0000ff;">="#aa0000"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="green"</span><span style="color: #ff0000;">
android:gravity</span><span style="color: #0000ff;">="center_horizontal"</span><span style="color: #ff0000;">
android:background</span><span style="color: #0000ff;">="#00aa00"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="blue"</span><span style="color: #ff0000;">
android:gravity</span><span style="color: #0000ff;">="center_horizontal"</span><span style="color: #ff0000;">
android:background</span><span style="color: #0000ff;">="#0000aa"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="yellow"</span><span style="color: #ff0000;">
android:gravity</span><span style="color: #0000ff;">="center_horizontal"</span><span style="color: #ff0000;">
android:background</span><span style="color: #0000ff;">="#aaaa00"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"><span style="color: #800000;">LinearLayout
</span><span style="color: #ff0000;">android:orientation</span><span style="color: #0000ff;">="vertical"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="第1行"</span><span style="color: #ff0000;">
android:textSize</span><span style="color: #0000ff;">="15pt"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="第2行"</span><span style="color: #ff0000;">
android:textSize</span><span style="color: #0000ff;">="15pt"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="第3行"</span><span style="color: #ff0000;">
android:textSize</span><span style="color: #0000ff;">="15pt"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"><span style="color: #800000;">TextView
</span><span style="color: #ff0000;">android:text</span><span style="color: #0000ff;">="第4行"</span><span style="color: #ff0000;">
android:textSize</span><span style="color: #0000ff;">="15pt"</span><span style="color: #ff0000;">
android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
android:layout_weight</span><span style="color: #0000ff;">="1"</span> <span style="color: #0000ff;">/></span>
<span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span></span></span></span></span></span></span></span></span></span></span></span>
<span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS;
</span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> ch07demos.SrcDemos
{
[Activity(Label </span>= <span style="color: #800000;">"</span><span style="color: #800000;">Demo01LinearLayout</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Demo01LinearLayout : Activity
{
</span><span style="color: #0000ff;">PRotected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle savedInstanceState)
{
</span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Demo01LinearLayout);
}
}
}</span>

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

最近幾天,Ice Universe 不斷披露有關 Galaxy S25 Ultra 的詳細信息,人們普遍認為這款手機將是三星的下一款旗艦智慧型手機。除此之外,洩密者聲稱三星只計劃升級一台相機

OnLeaks 現在與 Android Headlines 合作,首次展示了 Galaxy S25 Ultra,幾天前,他試圖從他的 X(以前的 Twitter)粉絲那裡籌集到 4,000 美元以上的資金,但失敗了。對於上下文,嵌入在 h 下面的渲染圖像

除了發布兩款新智慧型手機外,TCL 還發布了一款名為 NXTPAPER 14 的新 Android 平板電腦,其大螢幕尺寸是其賣點之一。 NXTPAPER 14 採用 TCL 標誌性品牌霧面液晶面板 3.0 版本

三星尚未就何時更新其 Fan Edition (FE) 智慧型手機系列提供任何提示。目前來看,Galaxy S23 FE 仍然是該公司的最新版本,於 2023 年 10 月年初推出。

Vivo Y300 Pro剛剛全面亮相,它是最薄的中階Android手機之一,配備大電池。準確來說,這款智慧型手機厚度僅為 7.69 毫米,但配備 6,500 mAh 電池。這與最近推出的容量相同

最近幾天,Ice Universe 不斷披露有關 Galaxy S25 Ultra 的詳細信息,人們普遍認為這款手機將是三星的下一款旗艦智慧型手機。除此之外,洩密者聲稱三星只計劃升級一台相機

Redmi Note 14 Pro Plus 現已正式成為去年 Redmi Note 13 Pro Plus 的直接後繼產品(亞馬遜售價 375 美元)。正如預期的那樣,Redmi Note 14 Pro Plus與Redmi Note 14和Redmi Note 14 Pro一起成為Redmi Note 14系列的主角。李

OnePlus的姊妹品牌iQOO的2023-4年產品週期可能即將結束;儘管如此,該品牌已宣布 Z9 系列的開發尚未結束。它的最終版,也可能是最高端的 Turbo+ 變體剛剛按照預測發布。時間
