zoukankan      html  css  js  c++  java
  • 控件布局_LinearLayout的嵌套

     1 import android.os.Bundle;
     2 import android.app.Activity;
     3 
     4 
     5 public class Layout03 extends Activity {
     6 
     7     @Override
     8     protected void onCreate(Bundle savedInstanceState) {
     9         super.onCreate(savedInstanceState);
    10         setContentView(R.layout.main);
    11     }
    12 }
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:orientation="vertical"
     4     android:layout_width="fill_parent"
     5     android:layout_height="fill_parent"
     6     >
     7     <LinearLayout 
     8         android:orientation="horizontal"
     9          android:layout_width="fill_parent"
    10            android:layout_height="fill_parent"
    11         android:layout_weight="3">
    12         <TextView
    13           android:text="red"
    14           android:gravity="center_horizontal"
    15           android:background="#aa0000"
    16           android:layout_width="wrap_content"
    17           android:layout_height="fill_parent"
    18           android:layout_weight="1"/>
    19        <TextView
    20           android:text="green"
    21           android:gravity="center_horizontal"
    22           android:background="#00aa00"
    23           android:layout_width="wrap_content"
    24           android:layout_height="fill_parent"
    25           android:layout_weight="1"/>
    26       <TextView
    27           android:text="blue"
    28           android:gravity="center_horizontal"
    29           android:background="#0000aa"
    30           android:layout_width="wrap_content"
    31           android:layout_height="fill_parent"
    32           android:layout_weight="2"/>
    33       <TextView
    34           android:text="yellow"
    35           android:gravity="center_horizontal"
    36           android:background="#aaaa00"
    37           android:layout_width="wrap_content"
    38           android:layout_height="fill_parent"
    39           android:layout_weight="1"/>
    40        </LinearLayout>
    41        
    42        
    43     <LinearLayout 
    44         android:orientation="vertical"
    45          android:layout_width="fill_parent"
    46            android:layout_height="fill_parent"
    47         android:layout_weight="1">
    48     <TextView
    49         android:text="row one"
    50         android:textSize="15pt"
    51         android:layout_width="fill_parent"
    52         android:layout_height="wrap_content"
    53         android:layout_weight="1"/>
    54     <TextView
    55         android:text="row two"
    56         android:textSize="15pt"
    57         android:layout_width="fill_parent"
    58         android:layout_height="wrap_content"
    59         android:layout_weight="1"/>
    60     <TextView
    61         android:text="row three"
    62         android:textSize="15pt"
    63         android:layout_width="fill_parent"
    64         android:layout_height="wrap_content"
    65         android:layout_weight="1"/>
    66     <TextView
    67         android:text="row four"
    68         android:textSize="15pt"
    69         android:layout_width="fill_parent"
    70         android:layout_height="wrap_content"
    71         android:layout_weight="1"/>
    72        </LinearLayout>
    73 </LinearLayout>
    74 <!-- 
    75  layout_weight属性:它的值是整型,用于指定空闲空间的分配比例
    76  -->

    实现该布局:

      1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      2     xmlns:tools="http://schemas.android.com/tools"
      3     android:layout_width="match_parent"
      4     android:layout_height="match_parent"
      5     android:orientation="vertical"
      6     android:paddingBottom="@dimen/activity_vertical_margin"
      7     android:paddingLeft="@dimen/activity_horizontal_margin"
      8     android:paddingRight="@dimen/activity_horizontal_margin"
      9     android:paddingTop="@dimen/activity_vertical_margin"
     10     tools:context=".MainActivity" >
     11     
     12     <!--第一步是一个textView  -->
     13     <TextView
     14         android:layout_width="match_parent"
     15         android:layout_height="wrap_content"
     16         android:gravity="center"
     17         android:text="@string/huang" />
     18     
     19     
     20     
     21     <LinearLayout
     22         android:layout_width="match_parent"
     23         android:layout_height="wrap_content"
     24         android:orientation="horizontal" >
     25 
     26         <LinearLayout 
     27             android:layout_width="0dp"
     28             android:layout_height="match_parent"
     29             android:orientation="vertical"
     30             android:layout_weight="1"
     31             >
     32             
     33             <ImageView
     34                 android:layout_width="wrap_content"
     35                 android:layout_height="wrap_content"
     36                 android:src="@drawable/feng"
     37               />
     38             
     39             <RadioGroup 
     40                  android:layout_width="wrap_content"
     41                     android:layout_height="wrap_content"
     42                 >
     43                 <RadioButton 
     44                  android:layout_width="wrap_content"
     45                     android:layout_height="wrap_content"
     46                     android:text="石头"
     47                     />
     48                 <RadioButton 
     49                  android:layout_width="wrap_content"
     50                     android:layout_height="wrap_content"
     51                     android:text="剪刀"
     52                     />
     53                 <RadioButton 
     54                  android:layout_width="wrap_content"
     55                     android:layout_height="wrap_content"
     56                     android:text="布"
     57                     />
     58                 
     59             </RadioGroup>
     60             
     61         </LinearLayout>
     62         
     63         <LinearLayout 
     64             android:layout_width="0dp"
     65             android:layout_height="match_parent"
     66             android:orientation="vertical"
     67             android:layout_weight="1"
     68             >
     69             
     70              <ImageView
     71                 android:layout_width="wrap_content"
     72                 android:layout_height="wrap_content"
     73                 android:src="@drawable/jian"
     74               />
     75              
     76              <RadioGroup 
     77                  android:layout_width="wrap_content"
     78                     android:layout_height="wrap_content"
     79                 >
     80                 <RadioButton 
     81                  android:layout_width="wrap_content"
     82                     android:layout_height="wrap_content"
     83                     android:text="石头"
     84                     />
     85                 <RadioButton 
     86                  android:layout_width="wrap_content"
     87                     android:layout_height="wrap_content"
     88                     android:text="剪刀"
     89                     />
     90                 <RadioButton 
     91                  android:layout_width="wrap_content"
     92                     android:layout_height="wrap_content"
     93                     android:text="布"
     94                     />
     95                 
     96             </RadioGroup>
     97             
     98         </LinearLayout>
     99    </LinearLayout>
    100     
    101     
    102     
    103     
    104     
    105     <!--第二步是一个Button  -->
    106     <Button
    107         android:layout_width="match_parent"
    108         android:layout_height="wrap_content"
    109         android:gravity="center"
    110         android:text="@string/action"
    111         />
    112     
    113     <!--第三步是一个LinearLayout,里面有两个TextView  -->
    114     <LinearLayout
    115         android:orientation="horizontal"
    116         android:layout_width="match_parent"
    117         android:layout_height="match_parent"
    118         >
    119         
    120         <TextView 
    121              android:layout_width="0dp"
    122                 android:layout_height="wrap_content"
    123                 android:text="结果"
    124                 android:layout_weight="1"
    125             />
    126         
    127          <TextView 
    128              android:layout_width="0dp"
    129                 android:layout_height="wrap_content"
    130                 android:text="测试结果"
    131                 android:layout_weight="1"
    132             />
    133     </LinearLayout>
    134 
    135 </LinearLayout>

     如果应用程序布局嵌套的越多性能就会降低

  • 相关阅读:
    LeetCode题解之Flipping an Image
    LeetCode 之Find Minimum in Rotated Sorted Array
    LeetCode题解Transpose Matrix
    LeetCode 题解之Minimum Index Sum of Two Lists
    LeetCode题解之Intersection of Two Linked Lists
    LeetCode 题解之Add Two Numbers II
    LeetCode题解之Add two numbers
    href="#"与href="javascript:void(0)"的区别
    有关ie9 以下不支持placeholder属性以及获得焦点placeholder的移除
    ie7下属性书写不规范造成的easyui 弹窗布局紊乱
  • 原文地址:https://www.cnblogs.com/LO-ME/p/3585062.html
Copyright © 2011-2022 走看看