小编Hug*_*eta的帖子

从RecyclerView Adapter调用过渡动画而不是Activity

我有一个带有RecyclerView的应用程序,里面装有一些卡片,借助我自己定制的RecyclerView(RV)适配器.然后我尝试按照本教程添加活动之间的转换.但是,如教程中所示,在Activity中创建Intent时会调用动画,而我的OnClick代码在RVAdapter中.这使我无法访问该方法所需的活动

Intent intent = new Intent(HomeActivity.this, TargetActivity.class);
intent.putExtra(TargetActivity.ID, Contact.CONTACTS[position].getId());
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
        // the context of the activity
        MainActivity.this,

        // For each shared element, add to this method a new Pair item,
        // which contains the reference of the view we are transitioning *from*,
        // and the value of the transitionName attribute
        new Pair<View, String>(view.findViewById(R.id.CONTACT_circle),
                getString(R.string.transition_name_circle)),
        new Pair<View, String>(view.findViewById(R.id.CONTACT_name),
                getString(R.string.transition_name_name)),
        new Pair<View, String>(view.findViewById(R.id.CONTACT_phone),
                getString(R.string.transition_name_phone))
);
ActivityCompat.startActivity(HomeActivity.this, intent, options.toBundle());
Run Code Online (Sandbox Code Playgroud)

我试图在其构造函数方法中将Activity对象传递给RVAdapter,但它只导致NullPointerExceptions.

这是我的RVAdapter代码:

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.AppVH>{


ArrayList<App> apps; …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-adapter android-recyclerview

4
推荐指数
1
解决办法
6644
查看次数

向下滑动以刷新Material Design

我一直在寻找新材料设计的实施,以便在RecyclerViews上刷新,从ActionBar下载加载圈,就像新的Gmail应用程序一样.我还没有找到类似的东西,只有一些SwipeRefreshLayout + RecyclerView示例.有谁知道如何做到这一点?

android pull-to-refresh material-design android-5.0-lollipop android-recyclerview

3
推荐指数
1
解决办法
5263
查看次数