Rak*_*tan 8 android rippledrawable android-5.0-lollipop android-elevation
我正在尝试将触摸反馈添加到LinearLayout,这类似于API级别21中的常规Button反馈,就像在此示例中一样,并且到目前为止还没有成功.
我已经定义了一个像这样的标准波纹可绘制:
<ripple xmlns:android="http://schemas.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>
Run Code Online (Sandbox Code Playgroud)
并使用了Google 在此提供的StateListAnimator :
<selector xmlns:android="http://schemas.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>
Run Code Online (Sandbox Code Playgroud)
在定义动画师和波纹可绘制之后,我将它们添加到我的LinearLayout中,如下所示:
<LinearLayout
android:id="@+id/linearLayout"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:background="@drawable/ripple"
android:stateListAnimator="@anim/touch_elevation">
Run Code Online (Sandbox Code Playgroud)
我的想法是使用这个LinearLayout作为一个按钮,因为它更容易插入各种类型的文本并在其中处理ImageView定位(而不是按钮drawables).
只要视图的背景根据此问题没有透明度,就可以单独添加涟漪效果或动画.
我不确定这是否是与上述问题相关的问题,但看到标准按钮设法同时采用波纹和高程动画反馈,我认为在其他视图中也可以实现这种效果.
任何洞察这个问题将不胜感激.
| 归档时间: |
|
| 查看次数: |
2831 次 |
| 最近记录: |