南郭不吹竿 2022-01-22 19:47 采纳率: 0%
浏览 33

请教一下为什么这个平移的效果展示不出来?


import androidx.appcompat.app.AppCompatActivity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Message;
import android.os.TestLooperManager;
import android.support.v4.app.INotificationSideChannel;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

public class MainActivity extends AppCompatActivity{

    private Button btn_translation;
    private Button btn_scale;
    private Button btn_rotation;
    private Button btn_alpha;
    private TextView text01;
    private Button btn_combination;


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

        initView();
        initAnimator1();

        MyThread1 myThread1 = new MyThread1();
        myThread1.start();

    }

    private void initAnimator1() {
        btn_translation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ObjectAnimator translationY = new ObjectAnimator().ofFloat(text01,"translationY",0f,1000f);
                translationY.setDuration(8000);
                translationY.start();

                Toast.makeText(MainActivity.this,"开始平移",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView() {
        btn_translation = (Button) this.findViewById(R.id.btn_translation);
        btn_scale = (Button) this.findViewById(R.id.btn_scale);
        btn_rotation = (Button) this.findViewById(R.id.btn_rotation);
        btn_alpha = (Button) this.findViewById(R.id.btn_alpha);
        btn_combination = (Button)this.findViewById(R.id.btn_combination);
        text01 = (TextView) this.findViewById(R.id.text01);
    }

    class MyThread1 extends Thread{
        @Override
        public void run() {
            btn_translation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    AnimatorSet set = new AnimatorSet();
                    ObjectAnimator scaleX = new ObjectAnimator().ofFloat(text01,"scaleX",1,2,1f);
                    ObjectAnimator scaleY = new ObjectAnimator().ofFloat(text01,"scaleY",1,2,1f);
                    set.setDuration(8000);
                    set.playTogether(scaleY,scaleX);
                    set.start();

                    new CountDownTimer(8000, 1000) {
                        public void onTick(long millisUntilFinished) {
                            text01.setText("倒计时:" + millisUntilFinished / 1000);
                        }
                        public void onFinish() {
                            text01.setText("完成");
                        }
                    }.start();

                    try {
                        Thread.sleep(1000*8);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });

        }
    }
}
  • 写回答

4条回答 默认 最新

  • 五一编程 2022-01-22 20:31
    关注

    线程里调用按钮的点击事件是不对的

    评论

报告相同问题?

问题事件

  • 创建了问题 1月22日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog