带有textview和imagebutton的listview项目行仅在imagebutton

时间:2015-07-07 19:50:00

标签: android android-listview rippledrawable

我的listview,文本和靠近它的ImageButton,将来应该在右侧。当我触摸文字或白色字段时,我想看到涟漪效果。我怎么能这样做?

此刻,当我触摸图像按钮时,只有涟漪效应。

这是我的list_item代码,我设置了一行的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/text"
    android:elevation="2dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="15dp"
    android:textColor="@android:color/black"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:layout_centerVertical="true"
    android:layout_marginTop="40dp"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    />

<ImageButton
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_delete_black_24dp"
    android:tint="#F44336"
    android:backgroundTint="@color/background"
    />


</RelativeLayout>

我发现,我必须使用LinearLayout,但我不知道,我必须如何正确使用它。我的ListView看起来像这样:

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:divider="#E0E0E0"
    android:dividerHeight="1dp"
    android:drawSelectorOnTop="true"
    >
    </ListView>

这是截图当前的截图: When i press on the red image button on the right side, there will be a riplpe effect around it. In all other places i touch, is no ripple effect.

有任何修复建议吗? ^^提前致谢

修改 我忘了说,当我定义了图像按钮时,listview中的OnItemClickListerner不再起作用了

1 个答案:

答案 0 :(得分:1)

据我所知,Ripple只显示可点击的视图(ListView的行,按钮或其他可点击的对象)。根据材料理论动画显示那些响应的对象(我不认为TextView需要响应点击)。在你的情况下,TextView没有显示,因为它只是不能正常工作但它适用于按钮(ImageButton是按钮)。

如果你仍然想要这只是使用这些第三部分库中的一个 -

https://github.com/lgvalle/Material-Animations 要么 https://github.com/balysv/material-ripple

这是最简单的方法!

相关问题