【问题标题】:Android Custom Button Ripple/pulse EffectAndroid 自定义按钮波纹/脉冲效果
【发布时间】:2016-11-13 05:46:25
【问题描述】:

我使用以下方法创建了一个自定义圆形按钮:

    <Button
    android:id ="@+id/StartButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start"
    android:background="@drawable/button_bg_round"
    android:padding="15dp"
    android:textSize="30sp"
    android:textStyle="bold"
    android:textColor="#ffffff"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

这里的button_bg_round定义如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="oval">
        <stroke android:color="#ffffff" android:width="5dp" />
        <solid android:color="#3aeaee"/>
        <size android:width="200dp" android:height="200dp"/>
    </shape>
</item>
</selector>

现在,我想在单击按钮时添加圆形波纹/脉冲效果/动画。我试图在 google 和 SO 上寻找可能的解决方案,但找不到与此类按钮相关的任何解决方案。任何帮助将不胜感激。

【问题讨论】:

    标签: android button android-custom-view effects


    【解决方案1】:

    你可以像这样让你可以绘制:

    <?xml version="1.0" encoding="utf-8"?>
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:color="@color/colorAccent"
        tools:targetApi="lollipop"> <!-- ripple effect color -->
        <item android:id="@android:id/background">
            <shape android:shape="oval">
                <stroke android:color="#ffffff" android:width="5dp" />
                <solid android:color="#3aeaee"/>
                <size android:width="200dp" android:height="200dp"/>
            </shape>
        </item>
    </ripple>
    

    其中 android:color insideripple 是效果的颜色。

    【讨论】:

    • 感谢您的帮助,但我尝试使用它,但它在圆形按钮内产生了涟漪效果;但我希望在按钮之外创建波纹。有什么帮助吗?
    • 如果你将按钮包装在 FrameLayout 中,背景是我给你的涟漪,然后在点击监听器上监听按钮,那么你可以触发 FrameLayout.performClick 或类似的方法。
    猜你喜欢
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    • 2022-07-18
    相关资源
    最近更新 更多