码迷,mamicode.com
首页 > 其他好文 > 详细

4种布局

时间:2016-04-05 12:23:33      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

1、相对布局

 1 <RelativeLayout 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="160px"
 5     android:paddingBottom="@dimen/activity_vertical_margin"
 6     android:paddingLeft="@dimen/activity_horizontal_margin"
 7     android:paddingRight="@dimen/activity_horizontal_margin"
 8     android:paddingTop="@dimen/activity_vertical_margin"
 9     tools:context=".MainActivity" >
10 
11     <TextView 
12         android:id="@+id/tv_title"
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:text="我是大的内容"
16         android:textColor="#ff0000"
17         android:textSize="20sp"
18         />
19     
20      <TextView 
21          android:layout_below="@id/tv_title"
22         android:layout_width="wrap_content"
23         android:layout_height="wrap_content"
24         android:text="我是小的内容"
25         android:textColor="#66000000"
26         android:textSize="14sp"
27         />
28      
29      <CheckBox
30          android:layout_width="wrap_content"
31          android:layout_height="wrap_content"
32          android:layout_alignParentRight="true"
33          android:layout_centerVertical="true"
34          />
35 
36 </RelativeLayout>

2、线性布局

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6 
 7     <Button
 8         android:id="@+id/button1"
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:text="Button" />
12 
13     <Button
14         android:id="@+id/button2"
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"
17         android:text="Button" />
18 
19     <ToggleButton
20         android:id="@+id/toggleButton1"
21         android:layout_width="wrap_content"
22         android:layout_height="wrap_content"
23         android:text="ToggleButton" />
24 
25     <ProgressBar
26         android:id="@+id/progressBar1"
27         style="?android:attr/progressBarStyleLarge"
28         android:layout_width="wrap_content"
29         android:layout_height="wrap_content" />
30 
31     <EditText
32         android:id="@+id/editText1"
33         android:layout_width="match_parent"
34         android:layout_height="wrap_content"
35         android:ems="10"
36         android:inputType="phone" >
37 
38         <requestFocus />
39     </EditText>
40 
41     <EditText
42         android:id="@+id/editText2"
43         android:layout_width="match_parent"
44         android:layout_height="wrap_content"
45         android:ems="10"
46         android:inputType="textPassword" />
47 
48     <EditText
49         android:id="@+id/editText3"
50         android:layout_width="match_parent"
51         android:layout_height="wrap_content"
52         android:ems="10" />
53 
54 </LinearLayout>

3、帧布局

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5    
 6     <TextView 
 7         android:visibility="visible"
 8         android:layout_width="match_parent"
 9         android:layout_height="match_parent"
10         android:text="第一帧"
11         android:gravity="center"
12         />
13     
14     <LinearLayout
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"
17         android:orientation="horizontal"
18         
19          >
20          <Button 
21              android:onClick="play"
22              android:layout_width="wrap_content"
23              android:layout_height="wrap_content"
24              android:text="播放"
25              />
26          
27           <Button 
28               android:onClick="pause"
29              android:layout_width="wrap_content"
30              android:layout_height="wrap_content"
31              android:text="暂停"
32              />
33         
34     </LinearLayout>
35       <ImageView 
36         android:id="@+id/iv"
37         android:layout_width="match_parent"
38         android:layout_height="match_parent"
39         android:src="@drawable/ic_launcher"
40         android:visibility="invisible"
41         />
42 
43 </FrameLayout>

4、表格布局

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5     
 6     <TableRow 
 7         android:layout_width="fill_parent"
 8         android:layout_height="wrap_content"
 9         >
10         <TextView 
11             android:layout_weight="1"
12             android:layout_width="0dp"
13             android:gravity="center"
14             android:layout_height="wrap_content"
15             android:text="芳芳"
16             
17             />
18          <TextView 
19             android:layout_weight="1"
20             android:layout_width="0dp"
21             android:gravity="center"
22             android:layout_height="wrap_content"
23             android:text="语言"
24             
25             />
26     </TableRow>
27     
28     
29      <TableRow 
30         android:layout_width="fill_parent"
31         android:layout_height="wrap_content"
32         >
33         <TextView 
34             android:layout_weight="1"
35             android:layout_width="0dp"
36             android:gravity="center"
37             android:layout_height="wrap_content"
38             android:text="芳芳"
39             
40             />
41          <TextView 
42             android:layout_weight="1"
43             android:layout_width="0dp"
44             android:gravity="center"
45             android:layout_height="wrap_content"
46             android:text="语言"
47             
48             />
49     </TableRow>
50 
51 </TableLayout>

 

 

 

二、帧布局的测试代码

 1 package com.example.commonlayout;
 2 
 3 import android.os.Bundle;
 4 import android.app.Activity;
 5 import android.view.Menu;
 6 import android.view.View;
 7 import android.widget.ImageView;
 8 
 9 public class MainActivity extends Activity {
10     private ImageView iv;
11     @Override
12     protected void onCreate(Bundle savedInstanceState) {
13         super.onCreate(savedInstanceState);
14         //setContentView(R.layout.activity_main);
15         setContentView(R.layout.test_frame);
16         iv = (ImageView)findViewById(R.id.iv);
17     }
18 
19 
20     public void play(View view)
21     {
22         iv.setVisibility(view.INVISIBLE);
23     }
24     
25     public void pause(View view)
26     {
27         iv.setVisibility(view.VISIBLE);
28     }
29     
30 }

 

4种布局

标签:

原文地址:http://www.cnblogs.com/zhongyinghe/p/5354478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!