ListView与CardViews奇怪的行为与保证金和填充
我已经实施了ListView
与CardView
s以下一些在线教程。包含列表ListView与CardViews奇怪的行为与保证金和填充
片段
<ListView android:id="@+id/interactions_list" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentStart="true" android:layout_marginTop="10dp" android:visibility="invisible" android:layout_alignParentTop="true" android:divider="#000000" android:dividerHeight="4dp" />
元件布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical"
>
<android.support.v7.widget.CardView
android:background="#00000000"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
android:id="@+id/cv">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dip">
<TableRow android:padding="5dip">
<ImageView
android:id="@+id/pkicon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="3dp"/>
<LinearLayout android:id="@+id/lnlayout"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_margin="3dip">
<TextView
android:id="@+id/pkname"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:textColor="#000000"
android:textSize="20sp"/>
<TextView
android:id="@+id/pknot"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:textColor="#606060"/>
</LinearLayout>
</TableRow>
</TableLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
现在我遇到当用户点击一个卡,这个截图是看到奇怪的行为:
卡片显示正确,但当轻拍时,连锁效果将覆盖LinearLayout
元素,并且卡片具有坚实的不透明背景。
预期行为:卡背后的背景保持白色,波纹效果仅出现在卡上。
请帮忙。
也许鲍勃迪伦的LinearLayout
width
和height
到wrap_content
可以解决
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
不幸的是没有工作。 –
这种情况正在发生的问题,因为你的父母的看法是线性布局纹波的原因正在创建使用就可以了
app:cardBackgroundColor="?selectableItemBackground"
或
android:background="?selectableItemBackground"
或
android:foreground="?selectableItemBackground"
在cardview布局
,并设置你点击收听此cardview布局不父即。 LinearLayout中。
背景提示无法使用。如何在卡上设置听众?此刻,我在整个列表中都有一个监听器'setOnItemClickListener'。 –
我希望你使用自定义适配器这里是参考如何设置点击监听器https://*.com/a/12596403/5492047和这一个http://androidforbeginners.blogspot.in/2010/03/clicking-按钮在列表视图row.html如果它不起作用让我知道。 –
非常感谢!这有助于。 –
您想让卡片内部的卡片可点击。目前在父级ListView上有一个onItemSelectedListener集,它在物品下面绘制波纹背景。也许你想用RecyclerView代替。 RecyclerView没有这种混乱的糖。你将负责点击监听器。从这里开始https://developer.android.com/training/material/lists-cards.html –