分类: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 無盡。

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

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

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。