I created a scaling animation for my checkbox. When it simply scales up and returns its original size again. It works expected all versions of Android except API 24 (Nougat).(API 25 and 26 not tested)
When I test my app, I tried to produce faults. This time I recognized when I change check before animation complete it gives the error in the below for API 24
A/art: art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: can't call void android.view.View.setScaleX(float) on null object
art/runtime/java_vm_ext.cc:470] in call to CallVoidMethodV
art/runtime/java_vm_ext.cc:470] from void android.animation.PropertyValuesHolder.nCallFloatMethod(java.lang.Object, long, float)
I decided to disable checkbox for a while then enable it. But I failed with it, because checkbox is in a viewholder in recyclerview. Changing one checkbox effects others as well. It was not a stable solution.
My CheckBox in a card
<CheckBox
android:id="@+id/card_bookmark_checkbox"
android:layout_width="0dp"
android:layout_height="@dimen/card_like_bookmark_size"
android:layout_gravity="bottom"
android:layout_marginEnd="@dimen/card_checkbox_margin"
android:background="@drawable/card_bookmark"
android:button="@null"
android:checked="false"
android:gravity="end"
app:layout_constraintBottom_toBottomOf="@+id/card_like_checkbox"
app:layout_constraintDimensionRatio="w,24:32"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="@+id/card_like_checkbox"
android:stateListAnimator="@animator/scale"/>
animator/scale
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<set>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="1.5"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleY"
android:valueTo="1.5"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="4dp"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="1.0"
android:startOffset="@android:integer/config_shortAnimTime"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleY"
android:startOffset="@android:integer/config_shortAnimTime"
android:valueTo="1.0"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:startOffset="@android:integer/config_shortAnimTime"
android:valueTo="0dp"
android:valueType="floatType" />
</set>
</item>
<item android:state_checked="false">
<set>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="1"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleY"
android:valueTo="1"
android:valueType="floatType" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="0dp"
android:valueType="floatType" />
</set>
</item>
</selector>
I found many great answers in this site but not for this one. Now I am stuck.
Thank you for reading this any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire