Android 控件(button)對(duì)齊方法實(shí)現(xiàn)詳解
布局方向。horizontal是讓所有的子元素按水平方向從左到右排列, vertical是讓所有的子元素按豎直方向從上到下排列。
2,android:gravity 與 android:layout_gravity的區(qū)別android:gravity是指定本元素的子元素相對(duì)它的對(duì)齊方式。
android:layout_gravity是指定本元素相對(duì)它的父元素的對(duì)齊方式。
例如:
下面這里的linearlayout的android:gravity設(shè)為right,有兩個(gè)子元素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>
這個(gè)main.xml里的LinearLayout也是有兩個(gè)子元素Button01和Button02。Button01的android:layout_gravity設(shè)為”left”,Button02的 android:layout_gravity設(shè)為”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是最簡(jiǎn)單的一個(gè)布局對(duì)象。它被定制為你屏幕上的一個(gè)空白備用區(qū)域,之后你可以在其中填充一個(gè)單一對(duì)象—比如,一張你要發(fā)布的圖片。所有的子元素將會(huì)固定在屏幕的左上角;你不能為FrameLayout中的一個(gè)子元素指定一個(gè)位置。后一個(gè)子元素將會(huì)直接在前一個(gè)子元素之上進(jìn)行覆蓋填充,把它們部份或全部擋?。ǔ呛?一個(gè)子元素是透明的)。
xml屬性
1,用xml文件來(lái)定義界面,然后Activity的setContentView方法根據(jù)xml文件里的定義來(lái)創(chuàng)建真正的控件對(duì)象。好比說(shuō)xml文件是設(shè)計(jì)圖紙,setContentView是生產(chǎn)機(jī)器,它依照?qǐng)D紙生產(chǎn)出各種各樣的杯具和洗具。
2,F(xiàn)rameLayout的xml屬性來(lái)自三個(gè)地方:繼承下來(lái)的,嵌套類定義的,自身類定義的。
3,具的屬性可查閱官方文檔。下面是剛才遇到的幾個(gè)屬性。
java代碼:
android:id
//這個(gè)xml屬性是繼承自android.view類的xml屬性。它為framelayout提供一個(gè)唯一識(shí)別符號(hào),之后,程序要用到它時(shí)可以用View.findViewById() 或Activity.findViewById()來(lái)找到它。
android:layout_width: 布局寬
android:layout_height: 布局高
//它們的取值是fill_parent或wrap_content。
fill_parent :在x軸或則y軸上充滿父容器的空間。
wrap_content :framelayout里的元素有多少寬高就多少寬高,
//這兩個(gè)屬性都是定義在android.widget.FrameLayout的嵌套類android.widget.FrameLayout.LayoutParams里。
android:background:背景
android:foreground :前景
相關(guān)文章
Android實(shí)現(xiàn)從相冊(cè)截圖的功能
這篇文章主要介紹了Android實(shí)現(xiàn)從相冊(cè)截圖的功能,簡(jiǎn)單介紹了Android實(shí)現(xiàn)從相冊(cè)截圖功能的步驟,供大家參考,感興趣的小伙伴們可以參考一下2016-01-01android實(shí)現(xiàn)來(lái)電靜音示例(監(jiān)聽(tīng)來(lái)電)
這篇文章主要介紹了手機(jī)來(lái)電鈴聲響起后,通過(guò)此代碼實(shí)現(xiàn)靜音而非掛斷的方法的相關(guān)資料2014-03-03android?Service基礎(chǔ)(啟動(dòng)服務(wù)與綁定服務(wù))
大家好,本篇文章主要講的是android?Service基礎(chǔ)(啟動(dòng)服務(wù)與綁定服務(wù)),感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12Android中標(biāo)簽容器控件的實(shí)例詳解
在Android開(kāi)發(fā)過(guò)程中,常常會(huì)遇到這樣的場(chǎng)景:我們展示一種物品或者為某一事物添加一些標(biāo)簽。比如說(shuō),我們買一件衣服,可以有以下幾種標(biāo)簽:杰克瓊斯,男士,運(yùn)動(dòng)等等。本文將實(shí)例介紹Android中標(biāo)簽容器控件的實(shí)現(xiàn)過(guò)程。2016-07-07基于Android實(shí)現(xiàn)ListView圓角效果
這篇文章主要為大家詳細(xì)介紹了基于Android實(shí)現(xiàn)ListView圓角效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06Android UI使用HorizontalListView實(shí)現(xiàn)水平滑動(dòng)
這篇文章主要為大家詳細(xì)介紹了Android UI使用HorizontalListView實(shí)現(xiàn)水平滑動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01Android應(yīng)用中炫酷的橫向和環(huán)形進(jìn)度條的實(shí)例分享
這篇文章主要介紹了Android應(yīng)用中炫酷的橫向和圓形進(jìn)度條的實(shí)例分享,文中利用了一些GitHub上的插件進(jìn)行改寫(xiě),也是一片很好的二次開(kāi)發(fā)教學(xué),需要的朋友可以參考下2016-04-04Android實(shí)現(xiàn)尋覓紅桃A的翻牌游戲
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)尋覓紅桃A的翻牌游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07Android APP與媒體存儲(chǔ)服務(wù)的交互
本文介紹如何在 Android 中,開(kāi)發(fā)者的 APP 如何使用媒體存儲(chǔ)服務(wù)(包含MediaScanner、MediaProvider以及媒體信息解析等部分),包括如何把 APP 新增或修改的文件更新到媒體數(shù)據(jù)庫(kù)、如何在多媒體應(yīng)用中隱藏 APP 產(chǎn)生的文件、如何監(jiān)聽(tīng)媒體數(shù)據(jù)庫(kù)的變化等等。2013-10-10Android編程讀取Assets所有文件(遍歷每一個(gè)文件夾)并存入sdcard的方法
這篇文章主要介紹了Android編程讀取Assets所有文件(遍歷每一個(gè)文件夾)并存入sdcard的方法,涉及Android針對(duì)文件與目錄的遍歷及I/O操作相關(guān)技巧,需要的朋友可以參考下2016-02-02