国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 控件(button)對齊方法實現詳解

2020-04-11 12:17:13
字體:
來源:轉載
供稿:網友
1,android:orientation
布局方向。horizontal是讓所有的子元素按水平方向從左到右排列, vertical是讓所有的子元素按豎直方向從上到下排列。

2,android:gravity 與 android:layout_gravity的區別android:gravity是指定本元素的子元素相對它的對齊方式。

android:layout_gravity是指定本元素相對它的父元素的對齊方式。
例如:
下面這里的linearlayout的android:gravity設為right,有兩個子元素Button01和Button02。
java代碼:
復制代碼 代碼如下:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:gravity=”right”
>
<Button android:text=”button01″ android:id=”@+id/Button01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”></Button>
<Button android:text=”button02″ android:id=”@+id/Button02″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”></Button>
</LinearLayout>

這個main.xml里的LinearLayout也是有兩個子元素Button01和Button02。Button01的android:layout_gravity設為”left”,Button02的 android:layout_gravity設為”right”
java代碼:
復制代碼 代碼如下:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<Button
android:layout_gravity=”left”
android:text=”button01″
android:id=”@+id/Button01″
android:layout_width=”wrap_content” a
ndroid:layout_height=”wrap_content”></Button>
<Button
android:layout_gravity=”right”
android:text=”button02″
android:id=”@+id/Button02″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</Button>
</LinearLayout>

FameLayout布局
FrameLayout是最簡單的一個布局對象。它被定制為你屏幕上的一個空白備用區域,之后你可以在其中填充一個單一對象―比如,一張你要發布的圖片。所有的子元素將會固定在屏幕的左上角;你不能為FrameLayout中的一個子元素指定一個位置。后一個子元素將會直接在前一個子元素之上進行覆蓋填充,把它們部份或全部擋?。ǔ呛?一個子元素是透明的)。

xml屬性
1,用xml文件來定義界面,然后Activity的setContentView方法根據xml文件里的定義來創建真正的控件對象。好比說xml文件是設計圖紙,setContentView是生產機器,它依照圖紙生產出各種各樣的杯具和洗具。
2,FrameLayout的xml屬性來自三個地方:繼承下來的,嵌套類定義的,自身類定義的。
3,具的屬性可查閱官方文檔。下面是剛才遇到的幾個屬性。
java代碼:
復制代碼 代碼如下:

android:id
//這個xml屬性是繼承自android.view類的xml屬性。它為framelayout提供一個唯一識別符號,之后,程序要用到它時可以用View.findViewById() 或Activity.findViewById()來找到它。
android:layout_width: 布局寬
android:layout_height: 布局高
//它們的取值是fill_parent或wrap_content。
fill_parent :在x軸或則y軸上充滿父容器的空間。
wrap_content :framelayout里的元素有多少寬高就多少寬高,
//這兩個屬性都是定義在android.widget.FrameLayout的嵌套類android.widget.FrameLayout.LayoutParams里。
android:background:背景
android:foreground :前景
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彭山县| 镇坪县| 富裕县| 青川县| 江油市| 松滋市| 石城县| 龙井市| 井陉县| 嘉定区| 分宜县| 龙川县| 东源县| 纳雍县| 霍邱县| 河西区| 六枝特区| 滦平县| 永福县| 宝清县| 通江县| 宕昌县| 石景山区| 安乡县| 邛崃市| 荥阳市| 临沭县| 额敏县| 新郑市| 宣城市| 阜康市| 屯留县| 宁河县| 城口县| 鄯善县| 眉山市| 永福县| 章丘市| 保康县| 西乌| 高平市|