我有以下ExpandableListView,其中包含group_item和child_items。我为子项添加了边距,这样我就可以用边框包裹孩子了。
我想知道我们可以用下面的边框包装ExpandableListView的子节点吗?
代码:
list_group.xml
<?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="55dip"
android:background="@drawable/trip_group_border"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:paddingLeft="7dip"
android:paddingRight="?android:attr/expandableListPreferredItemIndicatorRight"
/>
</LinearLayout>
list_item.xml
<?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="?android:attr/listPreferredItemHeight"
android:background="@drawable/trip_item_outer_border"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/trip_item_border"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:clickable="false"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:textAlignment="gravity"
android:textColor="@color/black2"
android:textSize="17dip" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:textAlignment="gravity"
android:textColor="@color/black2"
android:textSize="17dip" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:1)
我用这个,但是,我认为这不是一个好的解决方案!!
BaseExpandableListAdapter
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
RelativeLayout container = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_container, parent, false);
View itemView = null;//The actual view
container.addView(itemView);
if (childPosition == 0) {
container.setBackgroundResource(R.drawable.shape_itemblock_first);
} else if (isLastChild) {
container.setBackgroundResource(R.drawable.shape_itemblock_bottom);
} else {
container.setBackgroundResource(R.drawable.shape_itemblock);
}
return container;
}
shape_itemblock_first
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/divider_light" />
</shape>
</item>
<item android:left="1px" android:top="1px" android:right="1px" android:bottom="0dp">
<shape>
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>
shape_itemblock_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/divider_light" />
</shape>
</item>
<item android:left="1px" android:top="0dp" android:right="1px" android:bottom="1px">
<shape>
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>
shape_itemblock.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/divider_light" />
</shape>
</item>
<item android:left="1px" android:top="0dp" android:right="1px" android:bottom="0dp">
<shape>
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>
layout_container.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="1px"
android:background="@drawable/shape_itemblock"
android:layout_height="wrap_content">
</RelativeLayout>