2011-05-16 158 views
0

嗨我的Android應用程序有一個愚蠢的問題。Android佈局問題

目前,它看起來像這樣:

enter image description here

有使按鈕轉到中間底部的一種方式?我試過弄亂但是效果相同。還嘗試更改fill_parent/wrap_content,相對/線性佈局和重力。

這是.xml文件

enter image description here

千恩萬謝的屏幕截圖。

+2

XML的屏幕截圖? _Really?_請僅將實際的XML代碼包含到您的問題中,[由4個空格縮進](http://stackoverflow.com/editing-help)。 – 2011-05-16 16:29:04

+0

我不能...每次我複製和粘貼xml代碼...它不會顯示它。 – Superunknown 2011-05-16 16:33:11

+2

閱讀鏈接,amigo:http://stackoverflow.com/editing-help。 **使用4個空格縮進代碼塊** – 2011-05-16 16:34:06

回答

0

這兩個屬性添加到您的按鈕

android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true" 

這些一個到你的TextView:

android:layout_above="@id/insertion" 
android:layout_height="fill_parent" 

在這裏閱讀API參考: http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

+0

嗨我試過,但由於某種原因沒有效果。 – Superunknown 2011-05-16 17:18:57

+0

當列表中沒有項目時,此TextView由操作系統自動處理。如果這不起作用,您可能需要創建自己的活動,而不是預先打包的ListActivity並自定義您的顯示。 – Aleadam 2011-05-16 17:35:00

0

可能是你想使用線性佈局,而不是相對的... 使用LinearLayout,你可以放置你的物品,而不用考慮它們的相對位置。 您可以放置​​垂直線性佈局,並在其中放置另一個提示列表佈局。

<LinearLayout android:orientation="vertical"> 

<ListView android:width="fill_parent"android:weight="2" /> 
<Button android:width="wrap_content" android:weight="1" /> 

</LinearLayout> 

使用weight選項,您可以選擇使Button在ListView之前被繪製。

編輯:閱讀其他答案,我正在考慮如果你真的需要一個RelativeLayout來放置一個按鈕下的列表視圖。我想你應該學會在開始使用更復雜的東西之前學會如何處理簡單的視圖。如果LinearLayout解決您的問題,爲什麼不使用它?這是一個個人觀察...

1

有幾件事情你可以做到這一點,與你使用這個相對佈局將工作。這些行添加到您的按鈕部分

android:layout_below="@+id/android:empty" 
android:layout_alignParentBottom="true" 
android:layout_alignParentCenter="true" 
+0

如果您將它與ListActivity一起使用,您需要'android:empty',以便您可以使用默認的'setEmptyView()'函數和其他相關方法。 – kcoppock 2011-05-16 17:14:49

+0

嗨,出於某種原因,這似乎不會影響佈局。我仍然有相同的問題:/ – Superunknown 2011-05-16 17:25:04

+0

可能會添加fillparent到列表視圖,因爲它是空的,並在頂部被擠壓 – 2011-05-16 20:15:34