2013-08-22 139 views
-1

我有一個問題與我的列表視圖它應該有一個按鈕在頂部和下方是列表視圖。列表視圖不能正確顯示爲圖形佈局

但是,當我運行我的應用程序時,listview完全覆蓋了按鈕。這個問題的主要原因是什麼?

編輯 - 遺憾的大圖像,我不知道如何調整他們

enter image description here

enter image description here

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

<Button 
    android:id="@+id/buttonList" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:onClick="onClick" 
    android:text="@string/buttonShow" /> 

<ListView 
    android:id="@+id/listDays" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/buttonList"/> 

</RelativeLayout> 


public class SimpleListView extends ListActivity{ 

    String[] days; 
    Button mButtonList; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     mButtonList = (Button)findViewById(R.id.buttonList); 
     //mButtonList.setOnClickListener(btnListener); 

     //setContentView(R.layout.activity_list); 

     ListView lstView = getListView(); 
     lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 

     days = getResources().getStringArray(R.array.daysArray); 
     setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked, days)); 
     } 

回答

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:id="@+id/tab2" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.1" 
    android:orientation="vertical" > 

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

<LinearLayout 
    android:id="@+id/tab3" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.9" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 

</LinearLayout> 

+0

我試過這個,看起來好像會起作用,但問題仍然存在。我會添加java代碼,因爲那裏可能有問題嗎? – user2663646

+0

首先,你必須在你的Java類中調用SetContentVIew方法.. – Piyush

+0

我不得不評論說,因爲使用它會使活動崩潰。 「活動已停止」錯誤消息。 – user2663646

0

您需要提供的代碼,如果您希望我們能夠修復它。請提供您的xml佈局。但是,如果沒有進一步的信息,可能是因爲你的XML佈局有問題。下面是一個佈局可能會爲你工作:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
> 
<Button 
    android:id="@+id/header_button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
/> 
<ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:dividerHeight="1dip" 
     android:paddingLeft="1dp" 
     android:layout_below="@id/header_button" 
     /> 
</RelativeLayout> 
+0

我在xml和class的代碼中編輯過,xml非常相似,最初使用的是linearlayout。但改爲親屬也不幸沒有奏效。 – user2663646

0

您的XML代碼看起來大約右

你設置該屬性在代碼中的任何地方都可見。

+0

nope,絕對沒有那個地方,看起來很奇怪。 – user2663646

相關問題