當前位置:首頁 » 安卓系統 » android的相對布局

android的相對布局

發布時間: 2022-09-26 03:56:55

1. android 相對布局

其實你沒必要用RelativeLayout,用Linearlayout就行了。
每個圖片的layout_width="fill_parent"改為layout_width="wrap_content"
圖片寬度大小自適應,而不是全屏。

2. android開發,程序中如何修改控制項的相對布局

RelativeLayout layout =(RelativeLayout) findViewById(R.id.layout);
Button but = new Button(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(50,50);
lp.addRule(RelativeLayout.ALIGN_TOP,R.id.button);
lp.addRule(RelativeLayout.ALIGN_RIGHT,R.id.button);
layout.addView(but, lp);

關鍵是 addRule 方法 看代碼很顯然,是指定對齊button的頂端和右端。

另一種思路是,先在xml里配置好兩個button。不過先把上面的button的visibility 設置為gone,用到的時候在java代碼里設置為visible。

3. 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>

4. android 線性布局和相對布局的區別

線性布局(LinearLayout):在該標簽下的所有子元素會根據orientation屬性的值來決定是按行或者是按列來逐個顯示。代碼示例如下:

<LinearLayoutxmlns: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>

5. Android中常用的五種布局

常用五種布局方式,分別是:FrameLayout(框架布局),LinearLayout (線性布局),AbsoluteLayout(絕對布局),RelativeLayout(相對布局),TableLayout(表格布局)。

LinearLayout裡面又可分為垂直布局(android:orientation="vertical")和水平布局(android:orientation="horizontal" )

6. 關於Android里的線性布局和相對布局

新版本的默認就是相對布局了,你把<Relativelayout>,改成<Linearlayout>,便得,需要注意的是<Linearlayout>一般會指定android:orientation="vertical'屬性就是你這個線性是垂直線性還是橫向的線性,這里vertical是豎的,android:orientation="horizontal"就是橫的。而<Relativelayout>里的子View都必須指定它的相對位置,你改成Linearlayout的話注意把那些相對屬性去掉,具體你可網路下Linearlayout詳解、Relativelayout詳解。知道的更系統一點。

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

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

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

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

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

8. Android 相對布局 各控制項指之間的間距怎麼設置

<!-- android:layout_above 將該控制項的底部至於給定ID的控制項之上 android:layout_below 將該控制項的頂部至於給定ID的控制項之下 android:layout_toLeftOf 將該控制項的右邊緣和給定ID的控制項的左邊緣對齊 android:layout_toRightOf 將該控制項的左邊緣和給定ID的控制項的右邊緣對齊 android:layout_alignBaseline 該控制項的baseline和給定ID的控制項的baseline對齊 android:layout_alignBottom 將該控制項的底部邊緣與給定ID控制項的底部邊緣 android:layout_alignLeft 將該控制項的左邊緣與給定ID控制項的左邊緣對齊 android:layout_alignRight 將該控制項的右邊緣與給定ID控制項的右邊緣對齊 android:layout_alignTop 將給定控制項的頂部邊緣與給定ID控制項的頂部對齊 android:alignParentBottom 如果該值為true,則將該控制項的底部和父控制項的底部對齊 android:layout_alignParentLeft 如果該值為true,則將該控制項的左邊與父控制項的左邊對齊 android:layout_alignParentRight 如果該值為true,則將該控制項的右邊與父控制項的右邊對齊 android:layout_alignParentTop 如果該值為true,則將空間的頂部與父控制項的頂部對齊 android:layout_centerHorizontal 如果值為真,該控制項將被至於水平方向的中央 android:layout_centerInParent 如果值為真,該控制項將被至於父控制項水平方向和垂直方向的中央 android:layout_centerVertical 如果值為真,該控制項將被至於垂直方向的中央 --> 夠詳細了吧 學Android 到 推薦你去 移動App資訊站 適合新手

9. 為什麼相對布局中 android:layout_alignright 屬性表示「在指定控制項左邊」。

因為這是我們安卓系統的一種設定。而且相對布局他指的是在右邊,所以他也就是right。如果你不想讓它設定在右邊的話,你是可以選擇到左邊也就是left

熱點內容
伺服器電腦機房是幹嘛的 發布:2025-03-16 02:30:47 瀏覽:488
龍貝格演算法c語言 發布:2025-03-16 02:26:28 瀏覽:101
c語言字元串讀入 發布:2025-03-16 02:21:23 瀏覽:476
python爬蟲開發環境 發布:2025-03-16 02:19:55 瀏覽:626
androidondestory 發布:2025-03-16 02:12:49 瀏覽:862
軟體源碼侵權 發布:2025-03-16 02:06:54 瀏覽:287
給表添加欄位的sql 發布:2025-03-16 02:04:29 瀏覽:473
1除5演算法 發布:2025-03-16 02:02:57 瀏覽:757
oppo雲密碼本在哪裡 發布:2025-03-16 01:57:13 瀏覽:534
c語言定義pi的 發布:2025-03-16 01:51:08 瀏覽:603