如何为Custom ExpandableListview上的每个项目设置动画

时间:2014-09-04 12:58:55

标签: android android-animation expandablelistview

我使用This Tutorial来制作我的Custome Expandable列表视图,我需要在点击它的父项时将动画设置为项目。 (只是我点击的组必须有动画) 我搜索并发现我也可以使用这种方法。

   public void onGroupCollapse(int groupPosition)

但我不知道如何查看我的孩子并将动画设置为:(

这是我的动画代码:

  Animation animation = AnimationUtils.loadAnimation(childsanimationview.getContext(), R.anim.fadein);
            childsanimationview.setAnimation(animation);

这是我的适配器代码

public class MyExpandableListAdapter extends BaseExpandableListAdapter {

private ArrayList<Parent> parents;
private LayoutInflater inflater;

// public View childsanimationview ;
public MyExpandableListAdapter(Context c, ArrayList<Parent> parentsfrom) {
    // Create Layout Inflator
    parents = parentsfrom;
    //  childsanimationview=childsanimation;
    inflater = LayoutInflater.from(c);
}

//此函数用于膨胀父行视图

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

    final Parent parent = parents.get(groupPosition);

    // Inflate grouprow.xml file for parent rows
    convertView = inflater.inflate(R.layout.grouprow, parentView, false);
    // Get grouprow.xml file elements and set values
    ((TextView) convertView.findViewById(R.id.parent_name)).setText(parent.getParentName());
    ImageView parent_right_img = (ImageView) convertView.findViewById(R.id.parent_right_img);
    ImageView parent_left_img = (ImageView) convertView.findViewById(R.id.parent_left_img);

    // Change right && left arrow image on parent at runtime
    if (isExpanded == true) {
        parent_right_img.setImageResource(R.drawable.parent_opened);
        parent_left_img.setImageResource(R.drawable.parent_opened);
    } else {
        parent_right_img.setImageResource(R.drawable.parent_right_closed);
        parent_left_img.setImageResource(R.drawable.parent_left_closed);
    }
    //     checkbox.setOnCheckedChangeListener(new CheckUpdateListener(parent));

    return convertView;
}

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

    final Parent parent = parents.get(groupPosition);
    final Child child = parent.getChildren().get(childPosition);

    // Inflate childrow.xml file for child rows
    convertView = inflater.inflate(R.layout.childrow, parentView, false);

    TextView Product_Name = (TextView) convertView.findViewById(R.id.product_name);
    TextView Ingredient = (TextView) convertView.findViewById(R.id.ingredient);
    TextView Product_Price = (TextView) convertView.findViewById(R.id.product_price);
    ImageView Product_Image = (ImageView) convertView.findViewById(R.id.product_img);


    Product_Name.setText(child.getProductName());
    Ingredient.setText(child.getIngredient());
    Product_Price.setText(child.getProductPrice());
    Product_Image.setImageResource(child.getProductImg());

    //  Product_Image.setImageResource(getResources().getIdentifier("com.androidexample.customexpandablelist:drawable/setting" + parent.getParentName(), null, null));

    return convertView;
}


@Override
public Object getChild(int groupPosition, int childPosition) {
    return parents.get(groupPosition).getChildren().get(childPosition);
}

//Call when child row clicked
@Override
public long getChildId(int groupPosition, int childPosition) {
    /****** When Child row clicked then this function call *******/
    return childPosition;
}

@Override
public int getChildrenCount(int groupPosition) {
    int size = 0;
    if (parents.get(groupPosition).getChildren() != null)
        size = parents.get(groupPosition).getChildren().size();
    return size;
}

@Override
public Object getGroup(int groupPosition) {
    return parents.get(groupPosition);
}

@Override
public int getGroupCount() {
    return parents.size();
}

//Call when parent row clicked
@Override
public long getGroupId(int groupPosition) {
    return groupPosition;
}

@Override
public void notifyDataSetChanged() {
    // Refresh List rows
    super.notifyDataSetChanged();
}

@Override
public boolean isEmpty() {
    return ((parents == null) || parents.isEmpty());
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

@Override
public boolean hasStableIds() {
    return true;
}

}

我该怎么做?

我怎样才能获得我孩子观点的参考?

tanx

1 个答案:

答案 0 :(得分:1)

检查以下代码。创建一个动画对象并将其设置为您需要的视图。

convertView.startAnimation(animation);