1
在片段我RecyclerVIewCardView在RecyclerView无法点击
我的动态容器:
我的片段:
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?actionBarSize"
android:clipToPadding="false"
android:paddingBottom="8dp"
android:paddingLeft="8dp" />
我CardView:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="2dp"
app:cardElevation="2dp">
...
</android.support.v7.widget.CardView>
的OnClickListener:
holder.card.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Log.d("click","click");
}
});
为什么cardview无法点击?我做错了什么?
你确定问题是'CardView'本身吗?我的意思是,用另一种观点(例如'FrameLayout')是否有效? –
您是否正确设置onClickListener? –
holder.card.setOnClickListener(新View.OnClickListener(){ @覆盖 公共无效的onClick(视图v){ Log.d( “点击”, “点击”);} }); – gape