ems android 基础 weight linear 相对 context add padding
线性布局 LinearLayout:
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context="com.example.top3.MainActivity" >
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:hint="请输入注册用户名"/>
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:hint="请输入密码"
- />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:ems="5"
- android:hint="请再次输入密码" >
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:hint="请输入邮箱"/>
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_margin="10dip"
- android:background="@drawable/btn_bg"
- android:gravity="center"
- android:hint="注册" />
相对布局 RelativeLayout:
- 1 2<RelativeLayout
- 3xmlns:android="http://schemas.android.com/apk/res/android" 4android:layout_width="match_parent" 5android:layout_height="match_parent" 6> 7
- 8<EditText
- 9android:id="@+id/e1"10android:layout_width="fill_parent"11android:layout_height="wrap_content"12android:hint="请输入用户名"13/>14<EditText
- 15android:id="@+id/e2"16android:layout_below="@id/e1"17android:layout_width="fill_parent"18android:layout_height="wrap_content"19android:hint="请输入用户名" />20
- 21<Button
- 22android:id="@+id/b2"23android:layout_below="@id/e2"24android:layout_alignRight="@id/e2"25android:layout_width="wrap_content"26android:layout_height="wrap_content"27android:text="注册"28/>29<Button
- 30android:id="@+id/b1"31android:layout_below="@id/e2"32android:layout_toLeftOf="@id/b2"33android:layout_width="wrap_content"34android:layout_height="wrap_content"35android:text="登录"36/>37
- 38
帧布局 FrameLyaout:
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
- <TextView
- android:id="@+id/t1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#f00"
- android:height="300dp"
- android:width="300dp" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#0f0"
- android:height="100dp"
- android:width="150dp" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#00f"
- android:height="50dp"
- android:width="100dp" />
表格布局 TableLayout:
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="name"
- android:paddingLeft="20dp"
- android:textSize="16dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="20dp"
- android:textSize="16dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="20dp"
- android:textSize="16dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="15dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="15dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="15dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="15dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="achievement"
- android:paddingLeft="40dp"
- android:textSize="8dp"
- />
Android 基础 TOP3:Activity 的线性,相对,帧和表格布局的概括
来源: http://www.bubuko.com/infodetail-2014754.html