2010-07-14 105 views

回答

44

如果要從ExpandableListView中完全刪除分隔線,setDividerHeight對於父項目和子項目都可以。子分隔符將使用與普通分隔符相同的高度進行繪製,或由setDividerHeight()設置。

,我使用一個變通爲我們隱藏一個和取消隱藏另外一個,剛纔設置的相同顏色的分頻器和項目象下面這樣:

ExpandableListView expView = getExpandableListView(); 
expView.setGroupIndicator(null); 
expView.setChildIndicator(null); 
expView.setChildDivider(getResources().getDrawable(R.color.greywhite));   
expView.setDivider(getResources().getDrawable(R.color.white)); 
expView.setDividerHeight(2); 

setDividerHeight必須低於setChildDividersetDivider,或高度爲0。

等待更多的答案......

+0

節省了很多時間。 – Ganesh 2014-02-27 15:48:30

+0

當然,如果填充的間距很煩人,您可以將DividerHeight設置爲0,並在自定義適配器中使用的單元格中包含分隔線。 要防止底部項目有分隔符,如果index == getGroupCount() - 1 && index2 == getChildCount() - 1 – csga5000 2015-05-14 15:20:27

24

隱瞞孩子分壓器設置顏色爲透明#00000000

定義你的color.xml文件

<color name="transparent">#00000000</color> 

透明,然後設置子分隔

listView.setChildDivider(getResources().getDrawable(R.color.transparent)) 

或在佈局XML文件

<ExpandableListView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:childDivider="#00000000"/> 
+7

將分隔符設置爲透明色並不是真的會將其刪除。 – Sulby 2014-07-20 09:33:09

+7

或者您可以使用'android:childDivider =「@ android:color/transparent」' – cassioso 2014-12-19 15:46:25

+0

只有當列表背景的背景與列表元素顏色相同時,纔可以使用。如果你有洗背景的顏色和白色的元素,這將無法正常工作。 – 2016-09-27 18:16:45

0

設置的分隔器高度的expandableListView爲0

//setDividerHeight(0) 

,然後在headerView XML

<View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_gravity="bottom" 
     android:background="@android:color/darker_gray" 
     /> 
1

在底部添加視圖如果你想只刪除子分隔,您可以創建具有相同的顏色作爲孩子的背景顏色的繪製。然後將其設置爲您的孩子分隔線。

ShapeDrawable sd1 = new ShapeDrawable(new RectShape()); sd1.getPaint().setColor(YOUR CHILD ITEM BACKGROUND COLOR); mExpListView.setChildDivider(sd1);

0

您可以使用屬性

<ExpandableListView 
    android:id="@+id/interestlvExp" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:divider="@null"> 
</ExpandableListView> 

但是,這將刪除羣組列表分頻器和。

相關問題