導航:首頁 > 操作系統 > android線性布局

android線性布局

發布時間:2022-04-28 07:09:11

⑴ 在安卓中什麼是線性布局,表格布局,相對布局求詳細答案,急急急!!!!

線性布局(LinearLayout):在該標簽下的所有子元素會根據orientation屬性的值來決定是按行或者是按列來逐個顯示。代碼示例如下:
<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:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test" />

</LinearLayout>
而相對布局,則是根據控制項的相對位置而言,比如居於按鈕的左側或者右側,示例如下:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button1"
android:layout_alignTop="@id/button1"
android:text="@string/hello_world" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/app_name" />

</RelativeLayout>
分享

⑵ Android中常用的五種布局

Android
布局是應用界面開發的重要一環,在Android中,共有五種布局方式分別是:
線性布局:LinerLayout
表格布局:TableLayout
相對布局:RelativeLayout
絕對布局:AbsoluteLayout
幀布局:FrameLayout

⑶ Android線性布局和表格布局及其相對布局 都適用於哪些場景

線性布局適用於控制項呈線性排列場景(一個接著一個),此線性可以為橫向的線性與縱向的線性。
表格布局適用於控制項呈表格狀分布,如m行n列,像HTML中的表單。
相對布局適用於另一控制項或父控制項,如在某個控制項的左(右、上、下、中線對齊)或相對於父控制項左(右、上、下、中線對齊)。

布局是可以互相嵌套的,如父控制項(容器)是線性縱向布局,第一個子布局為相對,第二個是表格,第三個是線性...

Android布局的概念是從Swing及HTML的布局引申而來,與他們的排版都非常相似。

Android中還有一種絕對布局,與HTML中的DIV也非常相似,都是以絕對坐標定位的方式定位控制項,但這種布局難以匹配Android不同的屏幕尺寸及不同解析度,所以使用很少。

⑷ android 中線性布局怎樣使控制項居最右邊

在控制項中使用android:layout_gravity="right"

在線性布局中使用android:gravity="right"

前提條件是你的線性布局是vertical

否則就要用其他手段weight等

⑸ android的線性布局裡有幾個按鈕,怎樣控制按鈕之間的間距啊

線性布局裡面有兩種情況,
1、垂直布局:在每個按鈕上加上
//這個表示距上個控制項5dp距下個控制項5dp,相當於在上下各加了5dp的空白區域
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
2、水平布局:在每個按鈕上加上
//這個表示距左邊的控制項5dp距右邊的控制項5dp,相當於在左右各加了5dp的空白區域
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"

⑹ android 用線性布局還是相對布局好

線性布局(LinearLayout):在該標簽下的所有子元素會根據orientation屬性的值來決定是按行或者是按列來逐個顯示。代碼示例如下: <LinearLayout xmlns:android="schemas/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/test" /> </LinearLayout> 而相對布局,則是根據控制項的相對位置而言,比如居於按鈕的左側或者右側,示例如下: <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/button1" android:layout_alignTop="@id/button1" android:text="@string/hello_world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/app_name" /> </RelativeLayout>

閱讀全文

與android線性布局相關的資料

熱點內容
程序員入門很難嗎 瀏覽:101
70後程序員照片 瀏覽:191
一個普通程序員能幹多久 瀏覽:934
adobe的PDF轉換器 瀏覽:857
單片機數字碼表匯編 瀏覽:481
單片機開發用的軟體 瀏覽:156
程序員8個演算法題 瀏覽:402
php題庫系統 瀏覽:225
王牌戰爭文明重啟選什麼伺服器 瀏覽:657
簡述對稱加密法 瀏覽:662
c語言數學編程 瀏覽:994
F1B命令 瀏覽:630
cs命令快捷鍵 瀏覽:852
阿里雲購買伺服器如何用現金支付 瀏覽:695
pythontime等待 瀏覽:993
單片機串列通信方式 瀏覽:503
android表格demo 瀏覽:282
安卓怎麼讓相冊不顯示網頁 瀏覽:318
php文件系統源碼 瀏覽:731
易信java 瀏覽:505