麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 系統 > Android > 正文

android LinearLayout 布局實例代碼

2020-04-11 12:27:37
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?> 
<!--  
   <LinearLayout> 
       線性版面配置,在這個標簽中,所有元件都是按由上到下的排隊排成的 
 -->
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"> 
   <!-- android:orientation="vertical" 表示豎直方式對齊 
        android:orientation="horizontal"表示水平方式對齊 
        android:layout_width="fill_parent"定義當前視圖在屏幕上 
                     可以消費的寬度,fill_parent即填充整個屏幕。 
        android:layout_height="wrap_content":隨著文字欄位的不同 
        而改變這個視圖的寬度或者高度。有點自動設置框度或者高度的意思 

       layout_weight 用于給一個線性布局中的諸多視圖的重要度賦值。 
     所有的視圖都有一個layout_weight值,默認為零,意思是需要顯示 
     多大的視圖就占據多大的屏幕空 間。若賦一個高于零的值,則將父視 
     圖中的可用空間分割,分割大小具體取決于每一個視圖的layout_weight 
       值以及該值在當前屏幕布局的整體 layout_weight值和在其它視圖屏幕布 
     局的layout_weight值中所占的比率而定。 
     舉個例子:比如說我們在 水平方向上有一個文本標簽和兩個文本編輯元素。 
    該文本標簽并無指定layout_weight值,所以它將占據需要提供的最少空間。 
    如果兩個文本編輯元素每一個的layout_weight值都設置為1,則兩者平分 
    在父視圖布局剩余的寬度(因為我們聲明這兩者的重要度相等)。如果兩個  
   文本編輯元素其中第一個的layout_weight值設置為1,而第二個的設置為2, 
   則剩余空間的三分之二分給第一個,三分之一分給第二個(數值越小,重要 
              度越高)。 
    -->
    <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="2"> 

    <TextView
        android:text="row one"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/> 

    <TextView
        android:text="row two"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/> 

    <TextView
        android:text="row three"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/> 

    <TextView
        android:text="row four"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/> 

    </LinearLayout> 

</LinearLayout>

感覺這種形式有點像div+css的方式布局,不過這種方式的靈活性和div+css還是有些不及,主要是那android:layout_weight的值如何去確定,而且采用的是數值越小,重要度越高的方式,分配起來還得好好計算一下。

Java代碼  Views.java

復制代碼 代碼如下:

package com.cn.view; 

import android.app.Activity; 
import android.os.Bundle; 

public class Views extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
    } 
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产1区2区在线 | 中文字幕在线亚洲精品 | www.精品一区 | bt 自拍 另类 综合 欧美 | 国产精品一区二区三区在线 | 狠狠干五月天 | 黄色片在线免费播放 | 国产99久久久久久免费看农村 | 久久久久久久久久美女 | 国产成人精品日本亚洲语音 | 北原夏美av | 久久精品视频2 | 久久精品久久久久 | 精品国产91久久久久 | 成人不卡免费视频 | 免费视频观看 | 精品国产91一区二区三区 | 久久亚洲精品久久国产一区二区 | 激情小说色 | 牛牛a级毛片在线播放 | www久久久久久| 羞羞答答www网站进入 | av电影在线观看网站 | 羞羞视频2023 | 中文字幕在线播放一区 | 日韩视频在线一区二区三区 | 黄色片网站在线免费观看 | 日本免费中文字幕 | 全黄性性激高免费视频 | 凹凸成人精品亚洲精品密奴 | 成人午夜一区二区 | 久久久无码精品亚洲日韩按摩 | 视频一区二区在线观看 | 成人在线视频国产 | 日韩视频区 | 黄色毛片一级 | 麻豆视频观看 | 久草成人在线 | 欧美1区2区 | 精品一区二区三区免费毛片爱 | 亚洲综合视频网 |