【发布时间】:2016-06-13 03:25:45
【问题描述】:
我想在 ExpandableListView 中为孩子使用自定义动画(向下/向上滑动)。因此,如果我单击元素 #2,我希望父元素 #2 的子元素使用动画展开。并退出/关闭,当我再次单击父级时。
但是,我在将动画指向孩子本身时确实存在问题。我能得到的最接近的方法是使用“myListView.getChildAt(groupPosition).setAnimation(slide_down);”为父级设置动画。如下所示。 当我使用这段代码并单击元素 x 时,元素 x 将制作动画 - 但是应该制作动画的是孩子,而不是被点击的父。
我在 MainActivity 中的代码,其中“myAdapter”是适配器,“myListView”是 ExpandableListView:
ExpandableListAdapter myAdapter = new ExpandableListAdapter(context, arrRO);
final ExpandableListView myListView = (ExpandableListView) findViewById(R.id.reminderlistView);
myListView.setAdapter(myAdapter);
myListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
if (myListView.isGroupExpanded(groupPosition)) {
//Need to implement collapsing animation as well
myListView.collapseGroup(groupPosition);
} else {
boolean autoScrollToExpandedGroup = false;
myListView.expandGroup(groupPosition, autoScrollToExpandedGroup);
setupLayoutAnimation(groupPosition);
//
}
//telling the listView we have handled the group click, and don't want the default actions.
return true;
}
private void setupLayoutAnimation(int groupPosition) {
Animation slide_down = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
myListView.getChildAt(groupPosition).setAnimation(slide_down);
//myListView.setAnimation(slide_down);
}
我还包括了“myListView.setAnimation(slide_down);”,但是如果我使用它并单击一个元素,每个显示的元素(父母 + 孩子)都会制作这个小动画,我只想要它给孩子.
如果这有什么不同的话,每个父母总是只有一个孩子。
【问题讨论】:
标签: android animation parent-child expandablelistview slide