gpt4 book ai didi

android - 我们可以用边框包裹 ExpandableListView 的 child 吗

转载 作者:行者123 更新时间:2023-11-30 02:10:17 26 4
gpt4 key购买 nike

我有以下 ExpandableListView,其中包含 group_item 和 child_items。我为子项添加了边距,以便我可以用边框包裹所有子项。

enter image description here

我想知道我们可以用如下边框包裹 ExpandableListView 的子项吗?

enter image description here

代码:

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>

最佳答案

我用这个,,但是,我认为这不是一个好的解决方案!!

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>

关于android - 我们可以用边框包裹 ExpandableListView 的 child 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30208447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com