Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android recyclerview、数据绑定和子视图动画_Android_Android Animation_Android Recyclerview_Android Databinding - Fatal编程技术网

Android recyclerview、数据绑定和子视图动画

Android recyclerview、数据绑定和子视图动画,android,android-animation,android-recyclerview,android-databinding,Android,Android Animation,Android Recyclerview,Android Databinding,你能帮我找到一种不泄漏的方法来制作RecylcerView项目子项目的动画吗 我想创建一个两级抽屉菜单,其中菜单项位于由适配器创建的RecyclerView中。某些菜单项包含子项,此项可以在末尾用箭头打开,以将子项添加到父项下方的列表中。 当适配器检测到父项必须打开/关闭并显示/删除子项时,我想设置这些箭头的动画,使其旋转180度 整个过程都在进行中,但我对动画的解决方案不满意( 棘手的是,我正在使用数据绑定来用数据填充这些项目 下面是我的类,其中包含数据: public class MenuI

你能帮我找到一种不泄漏的方法来制作RecylcerView项目子项目的动画吗

我想创建一个两级抽屉菜单,其中菜单项位于由适配器创建的RecyclerView中。某些菜单项包含子项,此项可以在末尾用箭头打开,以将子项添加到父项下方的列表中。 当适配器检测到父项必须打开/关闭并显示/删除子项时,我想设置这些箭头的动画,使其旋转180度

整个过程都在进行中,但我对动画的解决方案不满意(

棘手的是,我正在使用数据绑定来用数据填充这些项目

下面是我的类,其中包含数据:

public class MenuItem extends BaseObservable {

    public ObservableField<String> name = new ObservableField<>();
    public ObservableBoolean selected = new ObservableBoolean(false);
    public ObservableBoolean isSubItem = new ObservableBoolean(false);
    public MenuItem parent;
    public List<MenuItem> subItems = new ArrayList<>(0);
    private DrawerAdapter.OnDrawerItemClickListener listener;
    /* It's a potencial leak */
    public View arrow;

    .....
    public void animateArrow(boolean isOpen) {
        if(arrow == null)
           return;

        float degrees = isOpen ? 180f : 0f;
        arrow.animate().roatate(degrees).setDuration(300).start();
    }

}
以下是我绑定到ViewHolder的方式:

public class DrawerItemHolder extends RecyclerView.ViewHolder {

    public DrawerItemBinder ui;

    public DrawerItemHolder(View itemView) {
        super(itemView);
        ui = DataBindingUtil.bind(itemView);
    }
}
@Override
public void onBindViewHolder(DrawerItemHolder holder, int position) {
    MenuItem item = items.get(position);
    if(!item.subItems.isEmpty())
        item.arrow = holder.ui.arrow;
    holder.ui.setData(item);
}
我附加箭头视图,仅显示包含子项的项目

当适配器决定打开一个项目时,它调用此方法:

private void openCategories(MenuItem item) {
    ...

    /* Animate to close state the already opened category's arrow */
    if(openedCategory != null)
        openedCategory.animateOpener(false);

    openedCategory = item;
     /* Animate to opened state the newly opened category */
    openedCategory.animateOpener(true);

    notifyItemRangeInserted(...);
}
openedCategory也是一个MenuItem,是对实际打开的父项的引用

当它想要关闭一个项目时,调用以下命令:

private void closeCategories() {
    if (openedCategory == null)
        return;

   ...
    notifyItemRangeRemoved(...);

     /* Animate to closed state the already opened category's arrow */
    openedCategory.animateOpener(false);
    openedCategory = null;
}
所以我的问题是,如何通过在MenuItem类中保留有关父项的引用来设置父项的子视图的动画,而不泄漏这些箭头视图

致以最良好的祝愿