安卓:永久提升浏览 [英] Android: Permanently elevate View

查看:110
本文介绍了安卓:永久提升浏览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 RecyclerView ,具有RippleEffect以及一个StateListAnimator(这是如下图所示):

I have a RecyclerView, that has a RippleEffect as well as a StateListAnimator (which is shown below):

anim_lift.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_enabled="true"
        android:state_pressed="true">
        <set>
            <objectAnimator
                android:duration="@android:integer/config_shortAnimTime"
                android:propertyName="translationZ"
                android:valueTo="8dp"
                android:valueType="floatType"/>
        </set>
    </item>
    <item>
        <set>
            <objectAnimator
                android:duration="@android:integer/config_shortAnimTime"
                android:propertyName="translationZ"
                android:valueTo="0"
                android:valueType="floatType"/>
        </set>
    </item>
</selector>

再次单击视图时

现在的问题是,如何总会有提升它被点击,然后当正在使用此XML的观点去提升它。

The question is, how would one elevate the view that is using this xml when it is clicked, and then de-elevate it when the view is clicked again.

推荐答案

这可以通过视图的选定状态来实现的。如果您单击查看您的setSelected(真),当你再次点击的setSelected(假)

This can be achieved by using the selected state of the View. If you click the View you setSelected(true) and when you click it again setSelected(false).

yourView.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        v.setSelected(!v.isSelected()); // toggle selected state
    }
});

选中状态,则可以通过StateListAnimator处理。您可以添加一个新的项目,以赶上 state_selected =真正的

<item android:state_selected="true">
    <set>
        <objectAnimator
            android:duration="@android:integer/config_shortAnimTime"
            android:propertyName="translationZ"
            android:valueTo="8dp"
            android:valueType="floatType"/>
    </set>
</item>

现在如果选择查看它会有 8DP 升高。如果它不选择StateListAnimator将降至通过对默认海拔0dp

Now if the View is selected it will have an elevation of 8dp. If it's not selected the StateListAnimator will fall through to the default elevation of 0dp.

这篇关于安卓:永久提升浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆