日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...

發(fā)布時間:2025/3/20 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

標題圖

UI的描述

對于Android應用程序中,所有用戶界面元素都是由View和ViewGroup對象構建的。View是繪制在屏幕上能與用戶進行交互的一個對象。而對于ViewGroup來說,則是一個用于存放其他View和ViewGroup對象的布局容器!

viewgroup.png

Android為我們提供了View和ViewGroup的兩個子類的集合,提供常用的一些輸入控件(比如按鈕,圖片和文本域等)和各種各樣的布局模式(比如線程布局,相對布局,絕對布局,幀布局,表格布局等)。

用戶界面布局

在你APP軟件上的,用戶界面上顯示的每一個組件都是使用層次結構View和ViewGroup對象來構成的,比如,每個ViewGroup都是不可見容器,每個ViewGroup視圖組用于組織子視圖View的容器,而它的子視圖View可能是輸入一些控件或者在某塊區(qū)域的小部件UI。如果你有了層次結構樹,你可以根據自己的需要,設計出一些布局,但要盡量簡單,因為越簡單的層次結構最適合性能。

要聲明布局,可以在代碼中實例化對象并構建,最簡單的方法也可以使用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網格布局

描述一下幾個重要的

線性布局:

指子控件以水平或垂直方式排列。

相對布局:

指子控件以控件之間的相對位置或子控件相對于父容器的位置排列。

幀布局:

指所有子控件均放在左上角且后面元素直接覆蓋在前面元素之上。

絕對布局:

指子控件通過絕對定位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網格布局

GridView其實是一個網格一樣的視圖組件,是一個ViewGroup的二維視圖。用適配器可以將布局進行填充。

gridview.png

ListView列表組件

ListView是一個用于顯示列表的可以滾動的視圖組,列表項也可以用適配器進行添加內容的。

listview.png

結語

本文主要講解 Android精通:View與ViewGroup,LinearLayout線性布局,RelativeLayout相對布局,ListView列表組件

下面我將繼續(xù)對Java、 Android中的其他知識 深入講解 ,有興趣可以繼續(xù)關注

小禮物走一走 or 點贊

送?

總結

以上是生活随笔為你收集整理的精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。