2013-01-06 79 views
0

您好所有即時得到我的按鈕很沮喪,我怎麼做,以便它停留在屏幕的底部,如何在屏幕的底部做成一個按鈕住宿

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

</LinearLayout> 

回答

0

添加空的文本視圖和按鈕之間的重量爲1的視圖。該視圖將在未使用的空間上展開,並將按鈕保留在底部。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 
</LinearLayout> 
1

你可以通過與RelativeLayout這樣的替換LinearLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /* this puts the textview at the top of the relative layout */ 
    android:layout_alignParentTop="true" 
    android:text="TextView" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /* this puts the textview1 at the bottom of the first textview */ 
    android:layout_below="@id/textView1" 
    android:text="TextView" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /* this puts the button at the bottom of the RelativeLayout */ 
    android:layout_alignParentBottom="true" 
    android:text="Button" /> 

</RelativeLayout> 

刪除註釋行,如果你複製和粘貼,因爲沒有在XML的代碼...

0

請將此代碼複製和使用,它會工作...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TextView" /> 
</LinearLayout> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

</LinearLayout> 
相關問題