2011-08-05 127 views
1

我想創建活動,並將按鈕放在屏幕的任何位置。安卓移動按鈕

但我無法弄清楚如何做到這一點。

例如:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
     <Button android:text="start" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:layout_width="wrap_content"></Button> 
    </LinearLayout> 

在這種情況下按鈕apears在屏幕的底部。但我希望按鈕高一點,但我不能。 那麼有什麼方法可以使用座標或其他方法將按鈕放在屏幕上嗎?

+0

正是你所想設計什麼樣的佈局? –

回答

1

試用FrameLayout

編輯:從網站:

的FrameLayout是佈局對象的最簡單的類型。它基本上是屏幕上的一個空白區域,您稍後可以填充一個對象 - 例如,您可以交換和輸出的圖片。 FrameLayout的所有子元素 都固定在 屏幕的左上角;您無法爲子視圖指定不同的位置。 隨後的子視圖將簡單地繪製在先前的視圖上, 部分或完全遮擋它們(除非較新的對象是透明的 )。

+0

下一次請爲您的鏈接添加一個小的說明,以便我們不會被迫訪問該網站以瞭解您的答案是否可靠。謝謝〜 – AlienWebguy

+0

謝謝你的提示:) –

3

嘗試將android:layout_marginBottom="10dp"添加到按鈕。 像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/linearLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"> 
<Button android:text="start" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|center" 
    android:layout_width="wrap_content" 
    android:layout_marginBottom="10dp"></Button> 
</LinearLayout> 
+0

它沒有幫助(( –

+1

)您是否嘗試過添加更高的值?'android:layout_marginBottom =「80dp」' – 2011-08-05 12:18:52

+0

我剛剛在eclipse中測試過,您可以調整距離底部的距離通過改變這個值 – 2011-08-05 12:23:30

1

使用相對佈局和線性佈局中。

<RelativeLayout> 
..... 
<LinearLayout> 
..... 
</LinearLayout> 
</RelativeLayout> 

並使用margin屬性。

android:layout_marginTop 
android:layout_marginRIght 
android:layout_marginBottom 
android:layout_marginLeft 

在你的情況..

android:layout_marginBottom="40dp" 

,因爲你需要,你可以提供的價值。

0

您可以使用以下方法:

android:layout_marginTop= ""