我真的很久沒有回到Android了,事實證明,我幾乎忘記了一切。我應該選擇哪種佈局?
我想構建這樣的UI:
按鈕項目1和項目2觸發移動到另一個頁面,而執行操作按鈕不到位的動作。廣告應該停靠在屏幕的底部。
我應該選擇哪種佈局來實現此UI? 我針對的是Android 2.2(如果有的話)。
我真的很久沒有回到Android了,事實證明,我幾乎忘記了一切。我應該選擇哪種佈局?
我想構建這樣的UI:
按鈕項目1和項目2觸發移動到另一個頁面,而執行操作按鈕不到位的動作。廣告應該停靠在屏幕的底部。
我應該選擇哪種佈局來實現此UI? 我針對的是Android 2.2(如果有的話)。
我相信去相對佈局有幫助。可能會有所幫助,雖然你可能想重新洗牌一下。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
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:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:text="@string/item1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="48dp"
android:text="@string/item2" />
<Button
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/ad_goes_here" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:layout_marginTop="62dp"
android:text="@string/perform_action" />
</RelativeLayout>
+1爲確切的捕獲,但請詳細說明你回答與例子,因爲他自己提到他忘記了一切 – ingsaurabh 2011-12-21 06:35:28
@ingsaurabh:是啊,編輯它.. :) – Ghost 2011-12-21 06:36:48
@AngryHacker:我插入按鈕在該廣告的位置。您隨時可以使用適合您廣告的確切說明進行更改。 – Ghost 2011-12-21 06:39:16
您可以使用android:orientation="vertical"
一個LinearLayout
。然而,還有很多其他的佈局能夠實現你想要的用戶界面。我寧願堅持LinearLayout
,因爲我可以將它設置爲垂直或水平。
如何確保廣告停靠在底部? – AngryHacker 2011-12-21 06:31:33
如果您需要將物品放置在底部,例如Rahul所說的相對佈局會有所幫助。你可以使用'android:layout_alignParentBottom'。看看這個問題 - http://stackoverflow.com/questions/2386866/how-to-align-views-at-the-bottom-of-the-screen – Hend 2011-12-21 06:38:03
您可以在此佈局中繼續使用相對佈局,您需要使用列表視圖(簡單)並在列表視圖的下方拖動按鈕。並在底部的地方您advertice SDK區域將被留
I think using Linear Layout is best
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/btn1"
android:text="Item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center"
/>
<Button
android:id="@+id/btn2"
android:text="Item2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center"
/>
<Button
android:id="@+id/btn3"
android:text="Perform Action"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center"
/>
<Button
android:id="@+id/btn4"
android:text="Ad Goes here"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center"
/>
</LinearLayout>
@ Dr.nik我試過表的佈局,但它是不切實際的。 – AngryHacker 2011-12-21 06:32:51
按照rahul請嘗試與相對佈局 – 2011-12-21 06:35:13