1.其他布局
.绝对布局
根标签<AbsoluteLayout
.表格布局
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </TableRow> </TableLayout>
.帧布局(播放器按钮)
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <view android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:background="#F44336"/> </FrameLayout>
2.布局中的单位:dp适配,不用px,字体sp
3.计算器
layout>caculor_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="C" android:textSize="30sp" android:background="@drawable/shape_rectangle"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="+/-" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="%" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:background="@drawable/shape_rectangle_orange" android:text="/" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="1" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="2" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="3" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:background="@drawable/shape_rectangle_orange" android:text="?" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="4" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="5" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="6" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:background="@drawable/shape_rectangle_orange" android:text="-" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="7" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="8" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="9" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:background="@drawable/shape_rectangle_orange" android:text="+" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:gravity="center_vertical" android:paddingLeft="40dp" android:text="0" android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="." android:background="@drawable/shape_rectangle" android:textSize="30sp"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:background="@drawable/shape_rectangle_orange" android:text="=" android:textSize="30sp"/> </LinearLayout> </LinearLayout>
drawable>shape_rectangle.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ffff"/> <stroke android:color="#333333" android:width="1dp"/> </shape>
drawable>shape_rectangle_orange.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#FFC107"/> <stroke android:color="#333333" android:width="1dp"/> </shape>
4.登录界面
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="@mipmap/Troye" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:drawableLeft="@mipmap/ic_launcher" android:text="QQ" android:textSize="50sp"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:hint="QQ号/手机号/邮箱" android:textSize="20sp" android:paddingLeft="30dp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="密码" android:textSize="20sp" android:paddingLeft="30dp" android:paddingTop="10dp" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" android:textSize="20sp"/> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="300dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="忘记密码?" android:paddingLeft="30dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="找回密码" android:layout_alignParentRight="true" android:layout_marginRight="30dp"/> </RelativeLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="登录即代表阅读并同意条款" android:layout_alignParentBottom="true" android:layout_marginBottom="50dp" android:layout_centerHorizontal="true" android:textColor="#F44336" /> </RelativeLayout>