欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Five Android layouts

程序员文章站 2022-07-21 21:17:54
线性布局: 相对布局: ......

线性布局:

 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     <!-- 上下左右全部填充100dp最终是已后加载的为准 -->
 7     <textview 
 8         android:id="@+id/tv_number"
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:layout_marginleft="30dp"
12         android:layout_margin="100dp"
13         android:text="请输入电话号码"/>
14    <edittext 
15        android:layout_width="match_parent"
16        android:layout_height="wrap_content"
17        android:hint="请输入电话号码" 
18        />
19     
20    
21    <button 
22        android:layout_width="wrap_content"
23        android:layout_height="wrap_content"
24        android:text="拨打"
25        />
26 
27 </linearlayout>

相对布局:

 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="match_parent"
 5     tools:context=".mainactivity" >
 6     <!-- 相对布局默认都是从左上角开始布局 -->
 7     <textview









8 android:id="@+id/tv_number" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:text="请输入电话号码" /> 12 13 <edittext 14 android:id="@+id/et_number" 15 android:layout_width="match_parent" 16 android:layout_height="wrap_content" 17 android:hint="请输入电话号码" 18 android:layout_below="@id/tv_number" 19 /> 20 21 <button 22 android:id="@+id/btn_number" 23 android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 android:text="拨打" 26 android:layout_below="@id/et_number" 27 /> 28 29 <button 30 android:layout_width="wrap_content" 31 android:layout_height="wrap_content" 32 android:text="按钮" 33 android:layout_torightof="@id/btn_number" 34 android:layout_below="@id/et_number" 35 /> 36 37 38 </relativelayout>