问题描述
我的问题是我的矢量可绘制对象完全不可见。因此我什至不知道动画是否有效。我不认为我需要一个支持库,至少谷歌没有在 AnimatedVectorDrawable 库的文档中提到它。那么如何在应用中看到矢量文件呢?
avd_minus_to_plus.xml
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:name="group"
android:pivotX="12"
android:pivotY="12">
<path
android:name="path_remove"
android:pathData="M 19 13 L 5 13 L 5 11 L 19 11 L 19 13 Z"
android:fillColor="@color/colorChipText"
android:trimPathEnd="0"/>
</group>
</vector>
</aapt:attr>
<target android:name="path_remove">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="pathData"
android:duration="300"
android:valueFrom="M 19 13 L 13.009 13 L 13.009 13 L 11.044 13 L 11.044 13 L 5 13 L 5 11 L 11.044 11 L 11.044 11 L 12.956 11 L 13.009 11 L 19 11 L 19 13 Z"
android:valueto="M 19 13 L 13 13 L 13 19 L 11 19 L 11 13 L 5 13 L 5 11 L 11 11 L 11 5 L 13 5 L 13 11 L 19 11 L 19 13 Z"
android:valueType="pathType"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</aapt:attr>
</target>
<target android:name="group">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="rotation"
android:duration="300"
android:valueFrom="0"
android:valueto="90"
android:valueType="floatType"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</aapt:attr>
</target>
Fab 图标应该是动画的
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_add_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:backgroundTint="@color/colorOrangeBright"
android:clickable="true"
android:padding="16dp"
android:src="@drawable/avd_minus_to_plus"
app:borderWidth="0dp"
app:fabSize="auto"
app:layout_anchor="@id/bottom_sheet_add_note"
app:layout_anchorGravity="end"
app:layout_constraintEnd_toEndOf="parent" />
晶圆厂和底板代码
FloatingActionButton fab_add_note = findViewById(R.id.fab_add_note);
fab_add_note.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (sheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else {
sheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
}
});
sheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onStateChanged(@NonNull View bottomSheet,int newState) {
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) fab_add_note.getDrawable();
switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
animatedVectorDrawable.start();
break;
case BottomSheetBehavior.STATE_EXPANDED:
animatedVectorDrawable.reset();
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet,float slideOffset) {
}
});
}
build.gradle(应用)
defaultConfig {
applicationId "com.example.example"
minSdkVersion 21
targetSdkVersion 29
versionCode 26
versionName "V3.0.1"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)