2012-03-21 79 views
0

當我使用linearlayout時,一切都像其假設一樣工作,除了我的按鈕位於頂部而不是屏幕底部。relativelayout讓我的按鈕停止工作

當我使用的RelativeLayout我的按鈕上應該像它的底部,但只適用於它停止工作後的第一個列表視圖項...

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

<Button android:id="@+id/plus" 
android:background="@drawable/selector" 
android:layout_width="fill_parent" 
android:layout_height="75dp" 
android:layout_alignParentBottom="true" 
/> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
> 

</ListView> 



    <TextView android:id="@android:id/empty" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:text="@string/helptxt1" 

    /> 


    </RelativeLayout> 

..

public void addListenerOnButton() { 

    final Context context = this; 

    button1 = (Button) findViewById(R.id.plus); 

    button1.setOnClickListener(new OnClickListener() { 

    // @Override 
     public void onClick(View arg0) { 


      createNote(); 
     // Intent intent = new Intent(context, QuoteEdit.class); 
      //   startActivity(intent); 

     } 

    }); 

} 


private void createNote() { 
Intent i = new Intent(this, QuoteEdit.class); 
startActivityForResult(i, ACTIVITY_CREATE); 

} 
+0

我不知道你能做到這一點。列表視圖可以無限擴展,並且不能放在滾動視圖中。因此,您可能無法在列表視圖下方放置按鈕。 – Shellum 2012-03-21 21:34:17

回答

0

你的按鈕不會工作,因爲當你使用相對佈局時,所有的視圖/按鈕被放置在相同的位置,除非你把它們放在彼此之上或之下。試着用你的佈局這樣做:

<Button 
    android:id="@+id/plus" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" /> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@+id/plus" > 
</ListView> 

,或者你可以添加一個onClick到您的按鈕:

<Button 
    android:id="@+id/plus" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:onClick="myClickMethod" /> 

,並在你的代碼

public void myClickMethod(View view) { 

     createNote(); 

} 
+0

這麼多工作。 – xaaam 2012-03-22 02:06:44