【问题标题】:How Can i set Animation for each items on Custom ExpandableListview如何为自定义 ExpandableListview 上的每个项目设置动画
【发布时间】:2014-09-04 12:58:54
【问题描述】:

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

   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;
}

}

我该怎么做?

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

坦克

【问题讨论】:

    标签: android android-animation expandablelistview


    【解决方案1】:

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

    convertView.startAnimation(animation);  
    

    【讨论】:

    • 坦克,它有帮助,但它为所有孩子设置动画,我如何将它设置为点击组孩子?
    • 在点击时设置一个标志并将 startAnimation() 设置为根据该标志工作
    猜你喜欢
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    相关资源
    最近更新 更多