我有一个问题是动画组指标.它激励不同位置的所有其他组指标.我试图通过标签区分它而没有效果.我想要的只是动画我点击的组.
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;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。