【问题标题】:Android ripple effect overlapped by imageView / GIFimageView / GIF重叠的Android波纹效果
【发布时间】:2015-09-14 12:13:09
【问题描述】:

我在回收视图中有一个列表项,我想在整个元素上获得涟漪效果 - 目前我的 GIF 与涟漪重叠。我不知道如何解决这个问题,经过研究已经尝试了很多方法,但没有任何效果。

这是我构建每个列表项的基础的特定 XML 文件。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/selector"
android:clickable="false">

<pl.droidsonroids.gif.GifTextView
    android:layout_width="84dp"
    android:layout_height="84dp"
    android:paddingTop="3dp"
    android:paddingBottom="3dp"
    android:paddingRight="1dp"
    android:paddingLeft="1dp"
    android:background="@drawable/a_present_for_you"
    />

<TextView
    android:id="@+id/textView"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textColor="@color/black"
    android:textSize="16sp"
    android:gravity="center_vertical"
    android:drawableRight="@drawable/ic_lock_open_blue_24dp"
    android:drawablePadding="16dp">
</TextView>

</LinearLayout>

有什么想法吗?

【问题讨论】:

    标签: android imageview ripple


    【解决方案1】:

    使用FrameLayout怎么样?用FrameLayout 而不是LinearLayout 包裹这两个元素,并使用您的自定义选择器设置此布局的android:foreground

    <?xml version="1.0" encoding="utf-8"?>
    
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:foreground="@drawable/selector">
    
    <pl.droidsonroids.gif.GifTextView
    android:layout_width="84dp"
    android:layout_height="84dp"
    android:paddingTop="3dp"
    android:paddingBottom="3dp"
    android:paddingRight="1dp"
    android:paddingLeft="1dp"
    android:background="@drawable/a_present_for_you"
    />
    
    <TextView
    android:id="@+id/textView"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textColor="@color/black"
    android:textSize="16sp"
    android:gravity="center_vertical"
    android:drawableRight="@drawable/ic_lock_open_blue_24dp"
    android:drawablePadding="16dp">
    </TextView>
    
    </FrameLayout>
    

    【讨论】:

    • 刚刚测试过,效果很好!但最后我还是选择了让 gif 与波纹重叠的方式,因为我意识到它在正确的上下文中看起来非常棒。
    【解决方案2】:

    只需使用以下属性:-

    android:background="?attr/selectableItemBackground" 用于简单的涟漪效应。 对于圆形波纹效果使用 android:background="?attr/selectableItemBackgroundBorderless"

    在主根目录内。

    【讨论】:

      【解决方案3】:

      波纹效果不会传播,因为您在同一个 LinearLayout 中有两个不同的背景。您可以尝试做的是将涟漪效果设置为整个 LinearLayout。

      【讨论】:

      • 是的,我认为这是问题所在,但我无法以不同的方式显示 gif。尝试使用android:drawableLeft="@drawable/a_present_for_you" 而不是android:background="@drawable/a_present_for_you",但它仍然重叠。将其设置为整个 LinearLayout 到底是什么意思?以为我已经通过在顶部设置 android:background="@drawable/selector" 来做到这一点。
      • &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="#40000000"&gt; &lt;item android:id="@android:id/mask"&gt; &lt;color android:color="@android:color/white" /&gt; &lt;/item&gt; &lt;/ripple&gt;
      • 尝试在您的 LinearLayout 中设置 android:clickable="true"
      猜你喜欢
      • 1970-01-01
      • 2017-05-12
      • 1970-01-01
      • 2016-06-02
      • 2021-01-16
      • 2017-05-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      相关资源
      最近更新 更多