說我想列出按鈕,以便最後一個錨定到屏幕的底部,我將如何去解決這個問題。根據我的理解,LinearLayout會給我按鈕的「列表」,但它會固定在頂部。另一方面,RelativeLayout將允許我錨定到底部,但每個元素都必須具有對下一個元素的引用,並且XML文件將以相反的順序(以便引用有效)。觸發器元素到屏幕底部而不使用RelativeLayout
我該如何解決這個問題?
編輯:道歉,這將是大約是我要尋找 -
說我想列出按鈕,以便最後一個錨定到屏幕的底部,我將如何去解決這個問題。根據我的理解,LinearLayout會給我按鈕的「列表」,但它會固定在頂部。另一方面,RelativeLayout將允許我錨定到底部,但每個元素都必須具有對下一個元素的引用,並且XML文件將以相反的順序(以便引用有效)。觸發器元素到屏幕底部而不使用RelativeLayout
我該如何解決這個問題?
編輯:道歉,這將是大約是我要尋找 -
我很難完全理解你的問題。 但我想你想要的是一個水平的按鈕列表,它錨定在屏幕底部?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- put your other views in here -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="cancel" />
<Button
android:id="@+id/button_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="ok" />
</LinearLayout>
</LinearLayout>
android:layout_gravity =「bottom」 - 當然! – stephenfin 2012-04-04 17:14:53
你可以嘗試添加一個額外的LinearLayout重量爲1〜佔用所有剩餘空間,並按鈕的列表推到活動的底部:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<Button
android:id="@+id/widget33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
示例XML爲單個按鈕被通過的LinearLayout到活動的底部被推;根佈局也是線性的。
謝謝!很適合我在屏幕底部定位按鈕,而不需要'RelativeLayout' – Konayuki 2017-02-02 08:26:52
爲了確保我們得到這個權利,我建議你彈出您喜愛的圖形編輯器(油漆,GIMP ...等),然後畫出你想要的東西,並把它添加爲一個圖像到您的文章。相對的佈局聽起來是正確的,但我相信社區中的其他人和我一樣會確保我們給出正確的建議。 – 2012-04-04 17:04:28