精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...
標(biāo)題圖
UI的描述
對于Android應(yīng)用程序中,所有用戶界面元素都是由View和ViewGroup對象構(gòu)建的。View是繪制在屏幕上能與用戶進行交互的一個對象。而對于ViewGroup來說,則是一個用于存放其他View和ViewGroup對象的布局容器!
viewgroup.png
Android為我們提供了View和ViewGroup的兩個子類的集合,提供常用的一些輸入控件(比如按鈕,圖片和文本域等)和各種各樣的布局模式(比如線程布局,相對布局,絕對布局,幀布局,表格布局等)。
用戶界面布局
在你APP軟件上的,用戶界面上顯示的每一個組件都是使用層次結(jié)構(gòu)View和ViewGroup對象來構(gòu)成的,比如,每個ViewGroup都是不可見容器,每個ViewGroup視圖組用于組織子視圖View的容器,而它的子視圖View可能是輸入一些控件或者在某塊區(qū)域的小部件UI。如果你有了層次結(jié)構(gòu)樹,你可以根據(jù)自己的需要,設(shè)計出一些布局,但要盡量簡單,因為越簡單的層次結(jié)構(gòu)最適合性能。
要聲明布局,可以在代碼中實例化對象并構(gòu)建,最簡單的方法也可以使用xml文件。
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
在Android中提供了幾個常用布局:
LinearLayout線性布局
RelativeLayout相對布局
FrameLayout幀布局
AbsoluteLayout絕對布局
TableLayout表格布局
GridLayout網(wǎng)格布局
描述一下幾個重要的
線性布局:
指子控件以水平或垂直方式排列。
相對布局:
指子控件以控件之間的相對位置或子控件相對于父容器的位置排列。
幀布局:
指所有子控件均放在左上角且后面元素直接覆蓋在前面元素之上。
絕對布局:
指子控件通過絕對定位x,y位置來決定其位置擺放。
表格布局:
指以行列的形式放置子控件,每一行是一個TableRow對象或者View對象。
圖片
LinearLayout線性布局
常用屬性:
id:為該組件添加一個資源id
orientation:布局中的排列方式,有兩種方式:
horizontal水平
vertical豎直
layout_width:布局的寬度,用wrap_content表示組件的實際寬度,match_parent表示填充父容器
layout_height:布局的長度,用wrap_content表示組件的實際長度,match_parent表示填充父容器
gravity:控制組件所包含的子元素的對齊方式
layout_gravity:控制該組件在父容器里的對齊方式
background:為該組件添加一個背景圖片
LinearLayout是一個視圖組,可以在一個方向垂直或者水平分布所有子項,用android:orientation屬性。
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="輸入賬號" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="輸入密碼" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登錄" />
RelativeLayout相對布局
RelativeLayout是一個相對布局的視圖組,用來顯示相對位置的子視圖類,在默認情況下,所有子視圖對會分布在左上角。
layout_alignParentTop:為true,視圖的上邊界與父級的上邊界對齊
layout_centerVertical:為true,將子類放置在父類中心
layout_below:將該視圖放在資源ID下方
layout_toRightOf:將該視圖放在資源ID右邊
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="你的名字" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true"
android:text="正確" />
GridView網(wǎng)格布局
GridView其實是一個網(wǎng)格一樣的視圖組件,是一個ViewGroup的二維視圖。用適配器可以將布局進行填充。
gridview.png
ListView列表組件
ListView是一個用于顯示列表的可以滾動的視圖組,列表項也可以用適配器進行添加內(nèi)容的。
listview.png
結(jié)語
本文主要講解 Android精通:View與ViewGroup,LinearLayout線性布局,RelativeLayout相對布局,ListView列表組件
下面我將繼續(xù)對Java、 Android中的其他知識 深入講解 ,有興趣可以繼續(xù)關(guān)注
小禮物走一走 or 點贊
送?
總結(jié)
以上是生活随笔為你收集整理的精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android xml 指纹动画,如何检
- 下一篇: android build获取ext,a