2015-05-31 16 views
-1

我試圖把一個按鈕放在中心&底部的線性佈局。我用下面的代碼,&它不工作。你能幫我嗎?如何在Android XML Linear Layout中設置中心底部的按鈕?

<Button 
      android:id="@+id/button1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:layout_gravity="center|bottom" 
      android:background="#C01831" 
      android:onClick="meonFb" 
      android:textColor="#ffffff" 
      android:layout_alignParentBottom="true" 
      android:text="Talk to Developer" /> 

,母親佈局,

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:layout_margin="12dp" 
     android:background="#f9f9f9" 
     android:orientation="vertical" 
     android:padding="10dp" > 

</LinearLayout> 
+1

嘗試'安卓重力=「中心|底」' –

+0

這需要按鈕文本中心和底部 –

+1

...這是你的要求爲:'設置在中央的按鈕bottom' –

回答

3

下面的代碼將會把按鈕中心底部的佈局。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_margin="12dp" 
    android:background="#f9f9f9" 
    android:orientation="vertical" 
    android:padding="10dp" 
    android:gravity="bottom|center"> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:layout_gravity="center|bottom" 
     android:background="#C01831" 
     android:onClick="meonFb" 
     android:textColor="#ffffff" 
     android:layout_alignParentBottom="true" 
     android:text="Talk to Developer" /> 

</LinearLayout> 
相關問題