Android的:如何实现发光效果时长pressing列表项?时长、如何实现、效果、列表

2023-09-04 03:51:53 作者:孤坟

使用默认的选择,长期pressing列表项导致其背景为两种颜色之间的过渡。

与一个替代选择下方的删除效果。根据这个问题,我需要一个动画来重现。我怎么会去这样做,在XML?

 < XML版本=1.0编码=UTF-8&GT?;
<选择
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目
        机器人:STATE_ pressed =真正的>
        <形状>
            [固体
                机器人:颜色=@色/ STATE_ pressed/>
        < /形状>
    < /项目>
    <项目
        机器人:state_focused =真正的>
        <形状>
            [固体
                机器人:颜色=@色/ state_focused/>
        < /形状>
    < /项目>
    <项目>
        <形状>
            [固体
                机器人:颜色=@色/ state_idle_grey/>
        < /形状>
    < /项目>
< /选择器>
 

解决方案 如何在Android开发中实现 移动效果和淡入效果

下面是list_selector_background的code:

        

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        <项目安卓state_window_focused =假机器人:可绘制=@机器人:彩色/透明/>
        <! - 
                尽管这两个点到同一资源,具有两种状态,以便
                可绘制将走出pressed状态时无效本身。
         - >
        <项目安卓state_focused =真正的机器人:state_enabled =假
                机器人:STATE_ pressed =真正的机器人:可绘制=@可绘制/ list_selector_background_disabled/>
        <项目安卓state_focused =真正的机器人:state_enabled =假
                机器人:可绘制=@可绘制/ list_selector_background_disabled/>
        <项目安卓state_focused =真正的机器人:STATE_ pressed =真
                机器人:可绘制=@可绘制/ list_selector_background_transition/>
        <项目安卓state_focused =假的Andr​​oid版本:STATE_ pressed =真
                机器人:可绘制=@可绘制/ list_selector_background_transition/>
        <项目安卓state_focused =真
                机器人:可绘制=@ +绘制/ list_selector_background_focus/>
< /选择器>
 

找到的on网络。

和它使用这种转型长期preSS点击:

 <过渡的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目机器人:可绘制=@可绘制/ list_selector_background_ pressed/>
    <项目机器人:可绘制=@可绘制/ list_selector_background_long preSS/>
< /转换>
 

找到的on网络太。

没有动画为该。请记住,让你的国家以相同的顺序,或者至少想想如果换成他们,顺序很重要。

Personnally,我喜欢当事情表现得有标准的方式,所以我只想让标准列表选择。

问候,  斯特凡

With the default selector, long-pressing a list item causes its background to transition between two colors.

Replacing the selector with the one below removes the effect. According to this question, I need an animation to reproduce it. How would I go about doing that in xml?

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true">
        <shape>
            <solid
                android:color="@color/state_pressed" />
        </shape>
    </item>
    <item
        android:state_focused="true">
        <shape>
            <solid
                android:color="@color/state_focused" />
        </shape>
    </item>
    <item>
        <shape>
            <solid
                android:color="@color/state_idle_grey" />
        </shape>
    </item>
</selector>

解决方案

Here is the code from list_selector_background :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_window_focused="false" android:drawable="@android:color/transparent" />
        <!--
                Even though these two point to the same resource, have two states so
                the drawable will invalidate itself when coming out of pressed state.
        -->
        <item android:state_focused="true" android:state_enabled="false"
                android:state_pressed="true"     android:drawable="@drawable/list_selector_background_disabled" />
        <item android:state_focused="true" android:state_enabled="false"
                android:drawable="@drawable/list_selector_background_disabled" />
        <item android:state_focused="true" android:state_pressed="true"
                android:drawable="@drawable/list_selector_background_transition" />
        <item android:state_focused="false" android:state_pressed="true"
                android:drawable="@drawable/list_selector_background_transition" />
        <item android:state_focused="true"
                android:drawable="@+drawable/list_selector_background_focus" />
</selector>

Found on the web.

And it uses this transition for long press clicks :

<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/list_selector_background_pressed"  />
    <item android:drawable="@drawable/list_selector_background_longpress"  />
</transition>

Found on the web too .

There is no animation for that. And remember to keep you states in the same order, or at least think about it if you swap them, order is important.

Personnally, I like when things behave in a standard way, so I would just let the standard list selector.

Regards, Stéphane