2015-01-13 18 views
1

我提出一個應用程序,我有以下XML文件:使用<include/>在android系統編程

<?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" 
    android:background="#f4f4f4" > 

      <ExpandableListView 
       android:id="@+id/lvExp" 
       android:layout_width="match_parent" 
       android:layout_height="325dp" /> 

      <Button 
       android:id="@+id/add_claim" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Add Claim" /> 
    </LinearLayout> 

我做了一個叫View_list按鈕希望只看到整個頁面的擴展列表視圖。我所做的就是創建一個新的XML文件,並添加follwing包括聲明:

<include android:id="@+id/lvExp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

不過,我意識到這將現在有兩個原因

1工作 - 沒有佈局ID

2-我只想要列表,而不是按鈕以及其他所有我要放入原始佈局的東西。將要發生的事情是,如果我將某些東西添加到列表中,我需要能夠查看它,而無需添加任何東西。因此

我的問題是這樣的:

如何找到佈局ID,我怎麼能防止整個佈局進行展示,並只顯示列表。我真的很感激一些建議。

回答

1

的包括應該說:

<include layout="@layout/View_list" 
     android:id="@+id/lvExp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

這包括在其他佈局View_list.xml佈局。

但我不明白爲什麼你會在這裏使用include如果你不想重新使用整個佈局,但只有列表部分。 include可以輕鬆使用其他佈局中的佈局,如果您只需要ListView,則只需使用ListView

編輯:我不知道了,如果我有你的問題,但我不會刪除答案,因爲你評論它。 如果您想要隱藏按鈕或其他視圖,只需單擊按鈕,即可將其可見性設置爲以編程方式消失。

+0

謝謝您的信息。你會如何建議我只使用列表呢?我明白你在說什麼,但我不知道如何去做。有什麼建議麼? –

+0

把這個列表本身是一個佈局文件。然後列表中的每個地方你想要它。 – pzulw

+0

謝謝。這很有道理。 –