android– 正常状态下按下状态透明度的涟漪效应

android– 正常状态下按下状态透明度的涟漪效应,第1张

概述我希望ViewGroup中的ImageView,当按下时,绘制波纹,这是有效的!但是当按下ViewGroup时,其中的ImageView应保持透明,否则ImageView背景可见:(实际上,您看到的颜色为alpha-orange,是按下时的纹波).这仅在设备API21中发生.使用设备API<21时,我使用选择器,当按下ViewGroup时,图像背景

我希望VIEwGroup中的ImageVIEw,当按下时,绘制波纹,这是有效的!但是当按下VIEwGroup时,其中的ImageVIEw应保持透明,否则ImageVIEw背景可见:(实际上,您看到的颜色为Alpha-orange,是按下时的纹波).

这仅在设备API 21中发生.使用设备API< 21时,我使用选择器,当按下VIEwGroup时,图像背景保持透明.layout.xml

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:ID="@+ID/item_detail_fIEld"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:paddingleft="@dimen/margin_left"    androID:paddingStart="@dimen/margin_left"    androID:paddingtop="@dimen/margin_top_item_fIEld"    androID:paddingBottom="@dimen/margin_bottom"    androID:baselineAligned="false"    androID:background="@drawable/layout"    androID:stateListAnimator="@anim/touch_raise"    androID:orIEntation="horizontal">...    <ImageVIEw        androID:ID="@+ID/item_detail_showfIEld_icon"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:background="@drawable/button_mini_oval"        androID:stateListAnimator="@anim/touch_raise"        androID:clickable="true"        androID:contentDescription="@null"        androID:scaleType="center"        androID:visibility="invisible"        androID:src="@drawable/show_button"/>...</linearLayout>

绘制/ button_mini_oval.xml

<selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <item androID:state_pressed="true">        <shape androID:shape="oval">            <solID androID:color="@color/primary_highlight" />        </shape>    </item>    <item>        <shape androID:shape="oval">            <solID androID:color="@androID:color/transparent" />        </shape>    </item></selector>

可绘制-V21 / button_mini_oval.xml

<ripple xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:exitFadeDuration="@androID:integer/config_shortAnimTime"    androID:color="?androID:colorControlHighlight">    <item androID:state_pressed="true">        <shape androID:shape="oval">            <solID androID:color="@androID:color/white" />        </shape>    </item>    <item>        <color androID:color="@androID:color/transparent" />    </item></ripple>

我在ripple xml中尝试了很多配置,添加了一个< selector>它可以工作(见下文),但是如果你只是点击ImageVIEw,纹波就不可见了(涟漪动画似乎被剪掉了),只有你按下它才能看到涟漪……

在正常状态下,压力状态下的波纹和透明状态的组合是什么?

<ripple xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:exitFadeDuration="@androID:integer/config_shortAnimTime"    androID:color="?androID:colorControlHighlight">    <item>        <selector>            <item androID:state_pressed="true">                <shape androID:shape="oval">                    <solID androID:color="@androID:color/white" />                </shape>            </item>            <item>                <color androID:color="@androID:color/transparent" />            </item>        </selector>    </item></ripple>

解决方法:

删除androID:state_pressed =“true”,我找到了2个解决方案,但在这两种情况下我都丢失了touch_raise动画(为什么?):

带有蒙面纹波:

<ripple xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:exitFadeDuration="@androID:integer/config_shortAnimTime"    androID:color="?androID:colorControlHighlight">    <item androID:ID="@androID:ID/mask">        <selector>            <item>                <shape androID:shape="oval">                    <solID androID:color="@androID:color/white" />                </shape>            </item>            <item>                <color androID:color="@androID:color/transparent" />            </item>        </selector>    </item></ripple>

带有未掩盖的小纹波(好于1):

<ripple xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:exitFadeDuration="@androID:integer/config_shortAnimTime"    androID:color="?androID:colorControlHighlight">    <selector>        <item>            <color androID:color="@androID:color/transparent" />        </item>    </selector></ripple>

我不知道为什么添加< selector>就足够了在透明背景上有波纹!!!很多人都试图实现这一目标,但这不是谷歌的意图,相反,这种情况非常有用.

总结

以上是内存溢出为你收集整理的android – 正常状态下按下状态透明度涟漪效应全部内容,希望文章能够帮你解决android – 正常状态下按下状态透明度的涟漪效应所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1116158.html

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

发表评论

登录后才能评论

评论列表(0条)

保存