Java安卓 使用视图组 布局
生活随笔
收集整理的這篇文章主要介紹了
Java安卓 使用视图组 布局
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 線性布局 LinerLauout
線性布局可以是單行列視圖。行可以是水平或垂直的;
可以使用android:orientation
| android:orientation | horizonal和vertical |
| android:width | wrap_content和match_parent |
| adnroid:width | wrap_content和match_parent |
linelayout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#FFFAF0"android:gravity="center"android:text="TextView(顯示框)"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#FF4500"android:gravity="center"android:text="TextView(顯示框)"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#808080"android:gravity="center"android:text="TextView(顯示框)"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#000000"android:gravity="center"android:text="TextView(顯示框)"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /></LinearLayout>2. 表格布局 TableLayout
TableRow決定行數,里面的決定列數
tablelayout.xml
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><TableRow><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="測試11" /></TableRow><TableRow><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="測試21" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="測試22" /></TableRow><TableRow><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="測試31" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="測試32" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="測試33" /></TableRow></TableLayout>3. 框架布局 FrameLayout
次布局用于蕾西堆棧格式從下往上添加視圖,也就是一層一層往上覆蓋。
framelayout.xml
4. 相對布局 RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="${relativePackage}.${activityClass}" ><Buttonandroid:id="@+id/btn1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/hello_world" /></RelativeLayout>5. 絕對布局 RelativeLayout
絕對布局不推薦,就可以不看啦
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><CheckBoxandroid:id="@+id/checkBox1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="42dp"android:layout_y="92dp"android:text="CheckBox" /> <Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="22dp"android:layout_y="14dp"android:text="Button" /></AbsoluteLayout>總結
以上是生活随笔為你收集整理的Java安卓 使用视图组 布局的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 构建用户界面 Android 应用中一些
- 下一篇: Ubuntu伪分布式hadoop安装