简体   繁体   English

Android Studio 中的按钮动画

[英]Button animation in Android studio

image How to get this kind of animation in Android studio. image如何在 Android Studio 中获得这种动画。 I am creating a quiz app.我正在创建一个测验应用程序。 I want user to click a button and let the code check for answer and then change button animation as in the video.我希望用户单击一个按钮并让代码检查答案,然后像视频中一样更改按钮动画。

Create a file in res folder with name alpha_animation在 res 文件夹中创建一个名为alpha_animation文件

  <?xml version="1.0" encoding="utf-8"?>
<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromAlpha="1"
    android:toAlpha="0.05"
    android:repeatCount="5"
    android:repeatMode="reverse"
    />

now write this in you activity现在在你的活动中写下这个

    private Button mButton;
    private Animation mAlphaAnimation;


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

        // Get the application context
        mContext = getApplicationContext();
        mActivity = MainActivity.this;

        mButton = (Button) findViewById(R.id.btn);
        mAlphaAnimation =   AnimationUtils.loadAnimation(mContext,R.anim.alpha_animation);

        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Start the blink animation (fade in and fade out animation)
                mButton.startAnimation(mAlphaAnimation);
            }
        });
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM