Hide divider without hiding childDivider on ExpandableListView
-
19-04-2021 - |
質問
I can't find a way to hide dividers on an ExpandableListView without hiding the child dividers too.
Here is my code.
<ExpandableListView
android:id="@+id/activities_list"
android:background="@android:color/transparent"
android:fadingEdge="none"
android:groupIndicator="@android:color/transparent"
android:divider="@android:color/transparent"
android:childDivider="@drawable/list_divider"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
With this code, I get no dividers on groups but no child dividers neither. If I set android:divider
to "@drawable/list_divider"
I get both group and child dividers.
Thanks in advance!
解決
The only solution I found is to put the child divider directly into the children XML, this way:
<TextView
android:id="@+id/name"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView android:id="@+id/divider"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@drawable/list_divider" />
which is very very ugly but works.
But still, there should be a way to do that properly.
他のヒント
expListView.setDivider(null);
expListView.setDividerHeight(2);
this will work
Adding dividerHeight parameter to your ExpandableListView in your xml layout should do the trick
How about just add a line:
android:dividerHeight="0dp"
Actually, i face the similar problem. PD asks the divider and the childDivider are both existed and different, which bothers me much. I am looking for answers too.
In my opinion : -Remove divider in XML :
android:divider="@null"
android:dividerHeight="0dp"
-Draw divider in View getGroupView(..,..,..,..) :
View divider = new View(_context);
View dividerIDU = new View(_context);
RelativeLayout.LayoutParams rldivider = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, 1);
RelativeLayout.LayoutParams rldividerShort = new RelativeLayout.LayoutParams(
150, 3);
rldividerShort.setMargins(5, -1, 0, 0);
dividerIDU.setBackgroundColor(Color.RED);
divider.setLayoutParams(rldivider);
dividerIDU.setLayoutParams(rldividerShort);
divider.setBackgroundColor(Color.rgb(200, 200, 200));
((RelativeLayout) convertView).addView(divider);
((RelativeLayout) convertView).addView(dividerIDU);
-After you can set divider following group position.