大佬教程收集整理的这篇文章主要介绍了非按钮视图上的Android Ripple效果提升,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经定义了一个像这样的标准波纹可绘制:
<ripple xmlns:android="http://scheR_896_11845@as.android.com/apk/res/android" android:color="?android:colorControlHighlight"> <item android:id="@android:id/mask"> <shape android:shape="rectangle"> <solid android:color="?android:colOraccent" /> </shape> </item>
并使用了Google提供的StateListAnimator here:
<SELEctor xmlns:android="http://scheR_896_11845@as.android.com/apk/res/android"> <item android:state_enabled="true" android:state_pressed="true"> <objectAnimator android:duration="@android:Integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="@dimen/touch_raise" android:valueType="floatType" /> </item> <item> <objectAnimator android:duration="@android:Integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="0dp" android:valueType="floatType" /> </item>
在定义动画师和波纹可绘制之后,我将它们添加到我的LinearLayout中,如下所示:
<LinearLayout android:id="@+id/linearLayout" android:clickable="true" android:focusable="true" android:orientation="horizontal" android:BACkground="@drawable/ripple" android:stateListAnimator="@anim/touch_elevation">
我的想法是使用这个LinearLayout作为一个按钮,因为我更容易插入各种类型的文本并在其中处理ImageView定位(而不是按钮drawables).
只要视图的背景根据this问题没有透明度,就可以单独添加涟漪效果或动画.
我不确定这是否是与上述问题相关的问题,但看到标准按钮设法同时采用波纹和高程动画反馈,我认为在其他视图中也可以实现这种效果.
任何洞察这个问题将不胜感激.
以下是stateListAnimator和ripple drawable的示例:
<your.package.ForegroundLinearLayout android:layout_width="300dp" android:layout_height="300dp" android:layout_centerInParent="true" android:gravity="center" android:foreground="@drawable/bg_ripple" android:BACkground="#fff" android:clickable="true" android:stateListAnimator="@animator/animator_elevation"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/> </your.package.ForegroundLinearLayout>
结果:
编辑:ForegroundLinearLayout存在于支持设计库中.所以你可以使用android.support.design.internal.ForegroundLinearLayout
以上是大佬教程为你收集整理的非按钮视图上的Android Ripple效果提升全部内容,希望文章能够帮你解决非按钮视图上的Android Ripple效果提升所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。