折叠或展开时,Android expandablelistview组父级背景图像会发生变化

折叠或展开时,Android expandablelistview组父级背景图像会发生变化,第1张

概述我尝试在展开折叠或展开时交换expandablelistview组背景图像.但是背景图像没有正确交换.例如,当我展开第一组时,第二组或第三组的背景会被交换. 我正在使用RelativeLayout(组布局)和SimpleExpandableListAdapter(适配器).这是我做的: // Create 2 drawable background. One for collapse and on 我尝试在展开折叠或展开时交换expandableListvIEw组背景图像.但是背景图像没有正确交换.例如,当我展开第一组时,第二组或第三组的背景会被交换.

我正在使用relativeLayout(组布局)和Simpleexpandablelistadapter(适配器).这是我做的:

// Create 2 drawable background. One for collapse and one for expandprivate Drawable collapseBG,expandBG;private ExpandableListVIEw myVIEw;public voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.main);    collapseBG = getResources().getDrawable(R.drawable.Box_bg_header_collapse);    expandBG = getResources().getDrawable(R.drawable.Box_bg_header_expand);    myVIEw = (ExpandableListVIEw) findVIEwByID(R.ID.myVIEw);}myVIEw.setonGroupCollapseListener(new ExpandableListVIEw.OnGroupCollapseListener() {    public voID onGroupCollapse(int groupposition_c) {        myVIEw.getChildAt(groupposition_c).setBackgroundDrawable(collapseBG);    }});myVIEw.setonGroupExpandListener (new ExpandableListVIEw.OnGroupExpandListener() {    public voID onGroupExpand(int groupposition_e) {        myVIEw.getChildAt(groupposition_e).setBackgroundDrawable(expandBG);    }});

有谁知道如何使这个工作?

解决方法 我认为你应该制作自己的适配器,它扩展了Simpleexpandablelistadapter.在那个班级你应该覆盖

public VIEw getGroupVIEw(int groupposition,boolean isExpanded,VIEw convertVIEw,VIEwGroup parent) { VIEw result = super.getGroupVIEw(groupposition,isExpanded,convertVIEw,parent); if (isExpanded) {     result.setBackgroundDrawable(expandBG); } else {     result.setBackgroundDrawable(collapseBG); } return result;}

在onCreate函数中你应该写如下的smth:

myVIEw.setlistadapter (new YourExtendedSimpleexpandablelistadapter( ...... ));

希望它会对你有所帮助

总结

以上是内存溢出为你收集整理的折叠或展开时,Android expandablelistview组/父级背景图像会发生变化全部内容,希望文章能够帮你解决折叠或展开时,Android expandablelistview组/父级背景图像会发生变化所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1123472.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存