簡體   English   中英

Android Material Design視圖狀態更改與高程

[英]Android Material Design View State changes vs Elevation

我正在嘗試在我的應用程序中實現Material Design,但我無法理解使用StateListAnimator實現陰影或為視圖指定高程有什么區別。

以下是我正在談論的內容的鏈接:

StateListAnimator
海拔

我所看到的是兩者都可以做同樣的事情,為什么他們在v5.0中同時實現了?

StateListAnimator允許您為View屬性(包括elevation設置動畫。 默認的Button實現使用StateListAnimator來處理elevationtranslationZ更改,以響應禁用和按下的狀態更改。

因此,默認Button樣式不使用elevation屬性,而是使用stateListAnimator屬性。

以下是XML的示例:

res/animator/button_state_list_anim_material.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:state_enabled="true">
        <set>
            <objectAnimator android:propertyName="translationZ"
                            android:duration="@integer/button_pressed_animation_duration"
                            android:valueTo="@dimen/button_pressed_z_material"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="elevation"
                            android:duration="0"
                            android:valueTo="@dimen/button_elevation_material"
                            android:valueType="floatType"/>
        </set>
    </item>
    ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM