只需单击一下即可显示RecyclerView的波纹效果

时间:2019-01-07 17:18:26

标签: java android android-recyclerview

我的应用程序中有一个 RecyclerView ,并且将背景属性设置为其相对布局以实现波纹效果。会显示波纹,但只有当我点击并按住时,或者当我稍微触摸并移动手指时(在焦点对准时)。
但是,只需单击一下(打开一个新活动),波纹就不会显示。

我查看了this答案,该答案增加了50ms的延迟,但这并不理想。 其他几个这样的问题也没有令人满意的答案。
YouTube和Whatsapp等应用会显示涟漪,然后打开屏幕。他们也使用延迟吗?

这些是我设置为波纹的相对布局的属性:

android:background="?android:attr/selectableItemBackground"
android:foreground="?android:selectableItemBackground"
android:clickable="true"
android:focusable="true"

这是onclick方法(启动新活动):

RecyclerView recyclerView = findViewById(R.id.recyler);
recyclerView.addOnItemTouchListener
            (new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() {
                @Override
                public void onClick(View view, int position){                     
                 String selection = menuDataSet[position];
                 Toast.makeText(MainActivity.this, "Selected " + selection, Toast.LENGTH_SHORT).show();
                 openScreenFromMenu(position);
                }

是否也有一种很好的方法来显示简单点击的波动? (不使用延迟)

0 个答案:

没有答案
相关问题