【问题标题】:Ripple effect /click animation with LiveData使用 LiveData 的波纹效果/点击动画
【发布时间】:2020-03-22 23:03:45
【问题描述】:

我在 LinearLayout 中有项目。单击时,项目会打开其他活动。单击列表项时出现波纹效果。但是列表项是 LiveData,并且无法在该项上出现涟漪效果。因为涟漪效应需要很少的时间才能出现,而且 LiveData 速度很快。我能做些什么?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:foreground="@drawable/clicked">

clicked.xml:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/colorPrimaryDark">

    <item
        android:id="@android:id/mask"
        android:drawable="@color/colorPrimaryDark" />
</ripple>

【问题讨论】:

    标签: android animation click android-livedata ripple


    【解决方案1】:

    我解决了这个问题。我使用这些代码而不是波纹。

    android:background="@android:drawable/list_selector_background"
    

    或

    android:background="@drawable/on_press_animation"
    

    on_press_animation.xml:

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

    <item android:state_enabled="true" android:state_pressed="true" android:drawable="@color/colorPrimaryDark" />
    <item android:state_enabled="true" android:state_focused="true" android:drawable="@color/colorPrimaryDark" />
    <item android:state_enabled="true" android:state_selected="true" android:drawable="@color/colorPrimaryDark" />
    <item android:state_activated="true" android:drawable="@color/colorPrimaryDark" />
    
    <item android:drawable="@android:color/transparent"/>
    

    【讨论】:

      猜你喜欢
      • 2017-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 2014-08-21
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      相关资源
      最近更新 更多