简单动画无法使用<objectanimator>

时间:2017-04-07 05:45:15

标签: android animation

Android动画新手,从这里学习https://developer.android.com/guide/topics/resources/animation-resource.html 我做了我所教的,但似乎不够。动画无效,应用程序崩溃了。

我的文件代码:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.animationsexperiments.MainActivity">

    <TextView
        android:id="@+id/victim"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

</LinearLayout>

MainActivity.java

package com.example.android.animationsexperiments;

import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Get the object, you wanna target
        final TextView victim = (TextView) findViewById(R.id.victim);

        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(getApplicationContext(),
                        R.animator.animation);
                set.setTarget(victim);
                set.start();
            }
        });
    }
}
res / animator中的

animation.xml文件

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:propertyName="string"
        android:duration="1000"
        android:valueTo="@string/app_name"

        />
</set>

任何回答和评论都表示赞赏,提前致谢。

0 个答案:

没有答案