我是Android開發的新手,我試圖在cardview點擊上提升電梯效果。我在這個主題上找到了幾個教程 this one,this one和this answer on stackoverflow。 所有這些教程建議創建這樣CardView電梯觸摸
<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="6dp"
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文件,然後把它放到RES /阿尼姆目錄。然而,當我試圖把這段代碼放在res/anim/lift_on_touch.xml中時,它給了我錯誤「元素選擇器必須聲明」,並建議將此文件移動到動畫器或可繪製目錄。我將它移動到animator-v21目錄中,並且沒有錯誤,但它不起作用。在這種情況下我該怎麼辦?
PS:我把clickable和stateListAnimator屬性添加到我的CardView中。這是我的CardView:
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
app:cardElevation="2dp"
android:clickable="true"
android:stateListAnimator="@animator/lift_on_touch"
app:layout_constraintTop_toTopOf="@+id/top_guideline"
app:layout_constraintRight_toRightOf="@+id/right_guideline"
app:layout_constraintLeft_toLeftOf="@+id/left_guideline"
app:layout_constraintBottom_toBottomOf="@+id/inner_top_guideline" />
這應該是一個非常簡單的解決辦法:你的XML複製到'RES/animator'目錄NOT res/anim,編譯並重新運行 –
@ inner_class7我試過了,仍然沒有結果 –
也刪除了objectAnimator附近的''標籤 –