2

약간의 클릭 애니메이션을 추가하려고합니다. as shown here 내 리사이클 러 뷰에는 성공적이지만 실패합니다. 여기 내 코드 중 일부입니다. 내 CardView.xml을 내 ViewHolderRecycler보기 클릭 애니메이션

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

을 내 활동

@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); 
} 

내부

<?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/ripple-animation –

관련 문제