2

Я пытаюсь добавить анимацию щелчка as shown here к моему просмотру recycler но безуспешно. Вот некоторые из моего кода.анимация щелчка мышью ресайклера

Внутри моей деятельности

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    ... 
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view); 
    ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(this, R.dimen.card_item_offset); 
    mRecyclerView.addItemDecoration(itemDecoration); 

    mLayoutManager = new LinearLayoutManager(this); 
    mRecyclerView.setLayoutManager(mLayoutManager); 

    mAdapter = new CustomAdapter(this); 
    mRecyclerView.setAdapter(mAdapter); 
} 

Внутри моей ViewHolder

public CustomViewHolder(View itemView) { 
    super(itemView); 
    this.itemView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      /* on click stuff here */ 
     } 
    }); 
} 

Внутри моей CardView.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_loading" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardCornerRadius="4dp" 
    android:clickable="true" 
    android:background="?android:attr/selectableItemBackground"> 

    <TextView 
     android:id="@+id/card_message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</android.support.v7.widget.CardView> 

Не знаете, где проблема есть, но заранее спасибо за помощь =)

+0

рад помочь вам :) –

ответ

7

это называется мультипликационный эффект, который вы пытаетесь с фоном вместо переднего плана

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

вы также можете сделать это обычай слишком

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    android:color="@color/colorcode"> 

    <item 
     android:id="@android:id/mask" 
     android:drawable="@color/colorcode" /> 
</ripple> 

для поддержки в более старых версиях вы можете сделать так

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/colorcode" /> 
     </shape> 
    </item> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/colorcode" /> 
     </shape> 
    </item> 
</selector> 
+0

полная документация: http://guides.codepath.com/a ndroid/пульсация-анимации –

Смежные вопросы