android– 选择器内部的Ripple效果

android– 选择器内部的Ripple效果,第1张

概述当有人按下我的ImageView时,我想获得连锁效果,但是对于其他状态也有不同的绘图效果.我有一个非常简单的ImageView:<ImageViewandroid:id="@+id/image"android:layout_width="120dp"android:layout_height="120dp"android:clickable="true"/>

当有人按下我的ImageVIEw时,我想获得连锁效果,但是对于其他状态也有不同的绘图效果.

我有一个非常简单的ImageVIEw:

<ImageVIEw    androID:ID="@+ID/image"    androID:layout_wIDth="120dp"    androID:layout_height="120dp"    androID:clickable="true"    />

我添加我的背景:

mImage.setBackgroundResource(R.drawable.background_resource);

我的drawable看起来像这样:

<selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <item androID:state_selected="false">        <shape            xmlns:androID="http://schemas.androID.com/apk/res/androID"            androID:shape="oval">            <solID                androID:color="@androID:color/darker_gray"/>            <size                androID:wIDth="80dp"                androID:height="80dp"/>        </shape>    </item>    <item androID:state_selected="true" androID:state_pressed="false">        <shape            xmlns:androID="http://schemas.androID.com/apk/res/androID"            androID:shape="oval">            <solID                androID:color="@androID:color/holo_blue_bright"/>            <size                androID:wIDth="120dp"                androID:height="120dp"/>        </shape>    </item>    <item androID:state_pressed="true">        <ripple androID:color="@androID:color/holo_blue_dark">            <item androID:ID="@androID:ID/mask">                <shape androID:shape="oval">                    <solID androID:color="@androID:color/holo_blue_dark"/>                    <size                        androID:wIDth="120dp"                        androID:height="120dp"/>                </shape>            </item>        </ripple>    </item></selector>

当我点击时,背景消失而不是显示涟漪效果.其他州工作正常.知道我在这里做错了什么吗?

解决方法:

事实证明你已经得到了另一种方式,为了显示波纹,你需要将选择器包含在波纹中

即,xml应该看起来像

<ripple androID:color="@color/ripple_color">    <item androID:ID="@androID:ID/mask">        <!-- ripple mask goes here -->    </item>    <item>        <selector>            <!-- your selector goes here -->        </selector>    </item></ripple>

HTH.

总结

以上是内存溢出为你收集整理的android – 选择器内部的Ripple效果全部内容,希望文章能够帮你解决android – 选择器内部的Ripple效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1110844.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存