【问题标题】:listview item row with textview and imagebutton only show ripple effect on imagebutton带有 textview 和 imagebutton 的 listview 项目行仅在 imagebutton 上显示波纹效果
【发布时间】:2015-07-07 19:49:59
【问题描述】:

我有我的列表视图,旁边有一个文本和一个 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>

这是当前的屏幕截图:

有什么建议可以解决吗? ^^ 先谢谢了

编辑: 我忘了说,当我定义了图像按钮时,来自 listview 的 OnItemClickListerner 不再起作用了

【问题讨论】:

    标签: android android-listview rippledrawable


    【解决方案1】:

    据我所知,Ripple 仅显示给可点击视图(ListView 的行、按钮或其他可点击对象)。根据那些响应的对象显示的材料理论动画(我不认为TextView 需要在点击时响应)。在您的情况下,TextView 没有显示,因为它无法正常工作,但可以在按钮上工作(ImageButton 是按钮)。

    如果您仍然想要这个,只需使用这些第三部分库之一 -

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

    这是最简单的方法!

    【讨论】:

      猜你喜欢
      • 2017-05-01
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 2020-11-19
      • 1970-01-01
      • 2016-08-30
      • 2012-05-08
      • 2018-06-21
      相关资源
      最近更新 更多