Android– 可扩展ListView如何在不影响其他人的情况下为组指示器设置动画

Android– 可扩展ListView如何在不影响其他人的情况下为组指示器设置动画,第1张

概述我有一个问题是动画组指标.它激励不同位置的所有其他组指标.我试图通过标签区分它而没有效果.我想要的只是动画我点击的组.publicViewgetGroupView(intgroupPosition,booleanisExpanded,ViewconvertView,ViewGroupparent){...if(isExpanded){O

我有一个问题是动画组指标.它激励不同位置的所有其他组指标.我试图通过标签区分它而没有效果.我想要的只是动画我点击的组.

public VIEw getGroupVIEw(int groupposition, boolean isExpanded,    VIEw convertVIEw, VIEwGroup parent) {   ...      if(isExpanded){        ObjectAnimator animator =   ObjectAnimator.offloat(containerIndicator,"rotation",0,180f);        animator.setDuration(400);        animator.start();        //arrowImage.setimageResource(R.drawable.ic_accordion_open);        headerTitle.setTextcolor(mContext.getResources().getcolor(R.color.euronics_blue));    }else{        if(arrowImage.getTag().toString().equalsIgnoreCase(getGroup(groupposition).name)) {            ObjectAnimator animator = ObjectAnimator.offloat(containerIndicator, "rotation", 180f,0);            animator.setDuration(400);            animator.start();        }     ... 

}

解决方法:

public class Consumptionexpandablelistadapter extends Baseexpandablelistadapter {    private Context mContext;    private List<ConsumptionItem> data;    private SparseBooleanArray expandState = new SparseBooleanArray();    public Consumptionexpandablelistadapter(Context context, List<ConsumptionItem> data) {        mContext = context;        this.data = data;        for (int i = 0; i < data.size(); i++) {            expandState.append(i, false);        }    }    public class VIEwHolderGroup {        private HashMap<Integer, VIEw> storedVIEws = new HashMap<Integer, VIEw>();        public VIEwHolderGroup() { }        public VIEwHolderGroup addVIEw(VIEw vIEw) {            int ID = vIEw.getID();            storedVIEws.put(ID, vIEw);            return this;        }        public VIEw getVIEw(int ID) {            return storedVIEws.get(ID);        }    }    @OverrIDe    public VIEw getGroupVIEw(final int groupposition, boolean isExpanded, VIEw v, VIEwGroup vIEwGroup) {        final ConsumptionItem consumptionItem = data.get(groupposition);        VIEw vIEw = v;        if (vIEw == null) {            vIEw = LayoutInflater.from(mContext).inflate(R.layout.List_item_consumption_group, vIEwGroup, false);            final TextVIEw name = (TextVIEw) vIEw.findVIEwByID(R.ID.name);            final TextVIEw serial = (TextVIEw) vIEw.findVIEwByID(R.ID.serial);            final ImageVIEw icon = (ImageVIEw) vIEw.findVIEwByID(R.ID.icon);            final ImageVIEw arrow = (ImageVIEw) vIEw.findVIEwByID(R.ID.arrow);            VIEwHolderGroup holder = new VIEwHolderGroup();            holder.addVIEw(name);            holder.addVIEw(serial);            holder.addVIEw(icon);            holder.addVIEw(arrow);            vIEw.setTag(holder);        }        VIEwHolderGroup holder = (VIEwHolderGroup) vIEw.getTag();        final TextVIEw name = (TextVIEw) holder.getVIEw(R.ID.name);        final TextVIEw serial = (TextVIEw) holder.getVIEw(R.ID.serial);        final ImageVIEw icon = (ImageVIEw) holder.getVIEw(R.ID.icon);        final ImageVIEw arrow = (ImageVIEw) holder.getVIEw(R.ID.arrow);        name.setText(consumptionItem.getname());        serial.setText(consumptionItem.getSerial());        arrow.setBackgroundResource(R.drawable.ic_keyboard_arrow_right_black_24dp);        if(consumptionItem.isstatus())            icon.setBackgroundResource(R.drawable.btn_ok_green);        else            icon.setBackgroundResource(R.drawable.btn_ok_red);        if (isExpanded && !expandState.get(groupposition)) {            animateExpand(arrow);            expandState.put(groupposition, true);        }        else if(!isExpanded && expandState.get(groupposition)) {            animateCollapse(arrow);            expandState.put(groupposition, false);        }        return vIEw;    }    private voID animateExpand(VIEw v) {        ObjectAnimator anim = ObjectAnimator.offloat(v, "rotation", 0, 90);        anim.setDuration(500);        anim.start();    }    private voID animateCollapse(VIEw v) {        ObjectAnimator anim = ObjectAnimator.offloat(v, "rotation", 90, 0);        anim.setDuration(500);        anim.start();    }    @OverrIDe    public VIEw getChildVIEw(int groupposition, int childposition, boolean isLastChild, VIEw vIEw, VIEwGroup vIEwGroup) {        final ConsumptionItem consumptionItem = data.get(groupposition);        final ConsumptionItem.Item item = consumptionItem.getItems().get(childposition);        vIEw = LayoutInflater.from(mContext).inflate(R.layout.List_item_consumption_child, vIEwGroup, false);        final TextVIEw month = (TextVIEw) vIEw.findVIEwByID(R.ID.month);        final TextVIEw date = (TextVIEw) vIEw.findVIEwByID(R.ID.date);        final TextVIEw indications = (TextVIEw) vIEw.findVIEwByID(R.ID.indications);        month.setText(item.getMonth());        date.setText(DateManager.getDateManager().getDateString(item.getDate()));        indications.setText(String.valueOf(item.getReadings()));        return vIEw;    }    @OverrIDe    public int getGroupCount() {        return data.size();    }    @OverrIDe    public int getChildrenCount(int groupposition) {        return data.get(groupposition).getItems().size();    }    @OverrIDe    public Object getGroup(int groupposition) {        return data.get(groupposition);    }    @OverrIDe    public Object getChild(int groupposition, int childposition) {        return data.get(groupposition).getItems().get(childposition);    }    @OverrIDe    public long getGroupID(int groupposition) {        return groupposition;    }    @OverrIDe    public long getChildID(int groupposition, int childposition) {        return childposition;    }    @OverrIDe    public boolean hasStableIDs() {        return true;    }    @OverrIDe    public boolean isChildSelectable(int groupposition, int childposition) {        return false;    }}

总结

以上是内存溢出为你收集整理的Android – 可扩展ListView如何在不影响其他人的情况下为组指示器设置动画全部内容,希望文章能够帮你解决Android – 可扩展ListView如何在不影响其他人的情况下为组指示器设置动画所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1120418.html

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

发表评论

登录后才能评论

评论列表(0条)

保存