찾다
php教程php手册【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”线性布局才会起作用。

二、示例—Demo01LinearLayout

1、设计界面

image

2、运行效果

image

 

3、添加Demo01LinearLayout.axml文件

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

<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>

4、添加Demo01LinearLayout.cs文件

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

<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>

运行观察效果。


성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기