Android中的线性布局
生活随笔
收集整理的這篇文章主要介紹了
Android中的线性布局
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1 線性布局
- 1.1 所有布局中的常用屬性
- 1.2 線性布局的常用屬性
- 1.3 線性布局示例
1 線性布局
1.1 所有布局中的常用屬性
布局重要屬性:
- android:layout_width :寬度
- android:layout_height :高度
- android:layout_padding :內邊距
- android:layout_margin :外邊距
1.2 線性布局的常用屬性
線型布局重要屬性:
- android:orientation: 方向
- android:layout_weight :權重,對布局中的控件進行設置。當只有1個控件設置時,數值任意,則當前空間的長度最后確定,會填充父容器剩余的空間;當所有空間都設置時需要將空間的寬度或者高度設置為0,然后會按比例分配空間所占用的空間。
- android:layout_gravity :重力,也就是控件相對于父容器的對齊位置。
注意:一般尺寸大小我們使用dp,而字體的大小則使用sp。
1.3 線性布局示例
xml文件如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><!--vertical:垂直的 horizontal:水平的--><!--layout_weight:權重--><!--android:layout_margin="20dp"android:padding="20dp"--><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:text="慕課慕課慕課慕課慕課慕課慕課"android:background="#ff0000"android:layout_weight="1"android:textSize="28sp"android:layout_gravity="bottom"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:text="慕課"android:background="#00ff00"android:layout_weight="2"android:textSize="28sp"android:layout_gravity="center"/><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:text="慕課"android:background="#0000ff"android:layout_weight="2"android:textSize="28sp"/></LinearLayout>總結
以上是生活随笔為你收集整理的Android中的线性布局的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高铁学校招生的标准?
- 下一篇: Android中的相对布局