【问题标题】:selectableItemBackgroundBorderless for textviewtextview 的 selectableItemBackgroundBorderless
【发布时间】:2015-08-12 09:32:42
【问题描述】:

我有一个TextView 用作按钮。我想添加属性selectableItemBackgroundBorderless 以在按下时产生圆形波纹效果。布局如下:

android:id="@+id/create_button"  
android:layout_width="wrap_content"
android:layout_height="54dp"
...
android:background="? android:attr/selectableItemBackgroundBorderless"

结果,确实是按下的时候出现了圆圈波纹效果,但是波纹走出了textview,而只是走出了textview的底部(因为textview的顶部是action bar)。

我的问题是,为什么会在 textview 底部产生涟漪效应?如您所知,我将android:layout_height 限制为54dp。为什么这个限制没有用?

【问题讨论】:

    标签: android textview geometry effect


    【解决方案1】:

    您必须使用?android:attr/selectableItemBackground 将涟漪效果保持在View 边界内。

    ?android:attr/selectableItemBackgroundBorderless 允许效果超出View

    【讨论】:

    • 是的,但是如何获得圆圈波纹效果?就像操作栏按钮按下效果一样。
    • 如果您在 Android 5.0+ 上运行您的应用程序,您应该拥有它。
    • 我在 Android 5.1 上运行。但是 rippe 从底部离开 textview。
    • 嗨,我今天解决了这个问题。我们需要为包含按钮的布局添加背景,然后撕裂效果将限制在按钮边框中。再次感谢您的帮助。
    • 我的问题是波纹被裁剪在 textView 的父级内。如何使波纹从 textView 的父级中消失?
    【解决方案2】:

    1.要限制视图内的涟漪效果,只需指定

    android:background="?attr/selectableItemBackground"
    

    在视图内。

    2.为了减少波纹效果边框,即在整个布局中显示波纹效果,您可以使用它。

    android:background="?attr/selectableItemBackgroundBorderless"
    

    3.更多可以查看链接Defining Custom Animation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-10
      • 2021-10-25
      相关资源
      最近更新 更多