2012-07-19 68 views
1

有人實現ExpandableListView裏面佈局嗎?我試圖做到這一點,我有高度問題。我想使它成爲「wrap_content」,以便在展開時查看完整展開的View。但不幸的是,對於「wrap_content」參數,我無法實現此結果。有人可以幫忙嗎?Android listview裏面的相對佈局

<?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="fill_parent" > 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" > 

<TextView 
    android:id="@+id/user" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_alignParentTop="true" 
    android:layout_below="@+id/rl" 
    android:layout_toRightOf="@+id/user" 
    android:paddingLeft="3dp" 
    android:text="Top User" 
    android:textColor="#000000" 
    android:textSize="22dp" /> 

<ExpandableListView 
    android:id="@+id/elvMain" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/user" 
    android:layout_above="@+id/about" > 
</ExpandableListView> 

<TextView 
    android:id="@+id/about" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_alignParentBottom="true" 
    android:text="Bottom About" 
    android:textColor="#6f6f6f" 
    android:textSize="24dp" 
    android:textStyle="bold" /> 
</RelativeLayout> 
</ScrollView> 
    </RelativeLayout> 

組一行ExpandableListView:

<?xml version="1.0" encoding="utf-8"?> 

    <TextView android:id="@+id/groupname" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:textStyle="bold" 
    android:textSize="20dp" 
    android:paddingLeft="40dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:background="@drawable/expanded_upper_selector" 
    android:gravity="center_vertical"/> 

子行

<?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="wrap_content" 
android:background="@drawable/ingredients_selector"> 



<TextView android:id="@+id/ingredients_second_layer_text" 
    android:textStyle="bold" 
    android:textSize="20dp" 
    android:paddingLeft="50dp" 
    android:paddingRight="50dp" 
    android:textColor="@color/dark_orange" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:gravity="center_vertical"/> 

+0

高度有什麼問題? – 2012-07-19 09:06:58

+0

高度「wrap_content」不包裝擴展列表視圖。展開的列表視圖無法完整顯示。只能看到它的一小部分。 – Stas 2012-07-19 09:10:51

+0

是的,我只是做了 – Stas 2012-07-19 09:12:13

回答

0

試試你的XML編輯一些-多少:

Your_XYZ_Ma in_XML ::

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:background="#000000" > 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#00ff00" > 

      <TextView 
       android:id="@+id/user" 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       android:paddingLeft="3dp" 
       android:text="Top User" 
       android:textColor="#111111" 
       android:background="#eeeeee" 
       android:textSize="22dp" /> 
      <ExpandableListView 
       android:id="@+id/elvMain" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" > 
      </ExpandableListView> 
      <TextView 
       android:id="@+id/about" 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       android:text="Bottom About" 
       android:textColor="#6f6f6f" 
       android:textSize="24dp" 
       android:textStyle="bold" /> 

     </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 

Group_Row_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" 
    android:orientation="vertical" > 

     <TextView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/groupname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#159357" // YOUR_BACKGROUND 
      android:gravity="center_vertical" 
      android:minHeight="?android:attr/listPreferredItemHeight" 
      android:paddingLeft="40dp" 
      android:text="Parent text" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textSize="20dp" 
      android:textStyle="bold" /> 

    </RelativeLayout> 

Child_Row_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" 
    android:orientation="vertical" > 


<TextView android:id="@+id/ingredients_second_layer_text" 
    android:textStyle="bold" 
    android:textSize="20dp" 
    android:paddingLeft="50dp" 
    android:paddingRight="50dp" 
    android:textColor="#ff2211" // YOUR_COLOR 
    android:text="Child Text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:gravity="center_vertical"/> 


</RelativeLayout> 
+0

非常感謝,但是我有一個循環依賴的錯誤。 – Stas 2012-07-19 11:33:33

+0

嗯,我認爲不。 – Stas 2012-07-19 11:38:08

+0

在哪個XML中您遇到循環依賴錯誤。 – 2012-07-19 11:39:05

0

看看這個鏈接 - http://about-android.blogspot.in/2010/04/steps-to-implement-expandablelistview.html

這裏只添加一個自定義文本。以類似的方式添加第二個。試試這個,如果有任何查詢,你可以隨意問。希望這會幫助你。

+0

我沒有看到任何xml那裏,我也看到簡單的ExpandableListView。未插入任何佈局。只是ExpandableListView – Stas 2012-07-19 11:32:57

+0

我已經明確寫在上面「這裏只添加一個自定義文本」。試試這個,你會得到結果。 – AkashG 2012-07-19 11:34:21