【发布时间】:2016-10-09 15:18:50
【问题描述】:
我正在尝试在棒棒糖前设备上为点设置动画,但我仍然得到:
java.lang.NullPointerException
at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505)
这是我的代码:
活动:
public class MyActivity extends BaseActivity {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
ImageView androidImageView = (ImageView) findViewById(R.id.animated);
androidImageView.setOnClickListener(v -> ((Animatable) androidImageView.getDrawable()).start());
}
my_activity 布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/animated"
android:layout_width="wrap_content"
app:srcCompat="@drawable/animated_dot"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
animated_dot.xml:
<?xml version="1.0" encoding="utf-8"?>
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/dot_1">
<target
android:animation="@anim/dot_animator"
android:name="dot_name" />
</animated-vector>
dot_animator:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="scaleX"
android:duration="250"
android:valueFrom="1.0"
android:valueTo="3.0"
/>
<objectAnimator
android:propertyName="scaleY"
android:duration="250"
android:valueFrom="1.0"
android:valueTo="3.0"
/>
</set>
和点_1:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="81.875"
android:viewportWidth="65.59"
android:width="24dp"
>
<path
android:fillColor="#FF000000"
android:pathData="M-0.01,32.82a32.81,32.81 0,1 1,65.61 0c0,28.94 -32.8,49.04 -32.8,49.04S-0.01,61.77 -0.01,32.82Z"
/>
</vector>
此崩溃与主要活动中的onClickListener 相关,并且仅在棒棒糖前设备上发生。如何在 API 16 上正确创建矢量比例动画?另外问题是在棒棒糖设备上这也不起作用,当我点击它时什么也没有发生。我正在使用库设计:23.4.0
【问题讨论】:
-
我的错误消息与
setupSetterAndGetter完全相同。从答案中我不清楚你的问题到底是什么。你能解释一下你做了什么来让你的代码正常工作吗?
标签: android android-animation android-vectordrawable