gpt4 book ai didi

android - 具有不同尺寸分隔线的可扩展列表,适用于父级和子级

转载 作者:行者123 更新时间:2023-11-29 17:36:34 24 4
gpt4 key购买 nike

我是 android 新手,这是我的第一个问题。

http://s11.postimg.org/tjhfoq7mb/123.png

我正在寻找创建与上图类似的东西。

  1. parent /组有 child = parent /组没有分隔线
  2. parent /组没有 child = parent /组有分隔线
  3. 最后一个 child = child 有一个完整的分隔符
  4. 不是最后一个 child = 不是一个完整的分隔符

有没有可能做到这一点。是是的?怎么办?

最佳答案

是的,这是可能的

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

// First of all add the parent line as View in custom_expandable_parent_view.xml and reference it
convertView = _lay.inflate(R.layout.custom_expandable_parent_view, null);
View parentLine = convertView.findViewById(your_parent_line_id);

if (isExpanded) {
// Now if the your list is expanded you dont have to show it
// so just hide it
parentLine.setVisibility(GONE);
}

return convertView;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

// now in add both childLine and parentLine in custom_expandable_child_view.xml
// reference both of them

convertView = _lay.inflate(R.layout.custom_expandable_child_view, null);
View parentLine = convertView.findViewById(your_id);
View childLine = convertView.findViewById(your_id);

// consider currently both line are showing in everychild.

if (isLastChild) {
// now, if it is last child then we have to show parentLine that means a long line. So we only hide childLine
childLine.setVisibility(View.GONE);
} else {
// now, if it is not last child then we have to show childLine that means a short line. for all child except the long one
// so here we hide the parent one
parentLine.setVisibility(View.GONE);
}

return convertView;
}

这就是我的代码,我已经做到了。因为我也想要和你一样的布局。我已经解释过了..因此,请根据您的要求进行更改。

enter image description here

关于android - 具有不同尺寸分隔线的可扩展列表,适用于父级和子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30237055/

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