log4lgb 2017-07-21 18:23 采纳率: 50%
浏览 1604
已采纳

Android 中 点击按钮调用AlphaAnimation的 start() 方法无效是什么原因?

代码如下:

 public class MainActivity extends Activity {

    private ImageView imageView;
    private Button start, stop;

    private AlphaAnimation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView = findViewById(R.id.gif);
        start = findViewById(R.id.startAnimation);
        stop = findViewById(R.id.stopAnimation);
        animation = new AlphaAnimation(1.0f, 0.0f);

        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                animation.setDuration(3000);
                animation.setStartOffset(0);
                imageView.startAnimation(animation);
            }
        });
    }

}

直接调用 View 的 startAnimation 方法可以启动动画,但是调用动画的 start 或startNow 方法却无效。

但是直接在 onCreate 方法中调用 start 或者 startNow 却可以启动,请问是什么原因?

  • 写回答

1条回答 默认 最新

  • RottenWang 2017-07-25 06:45
    关注

    大概,...也许...你的动画没和view绑定吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 9月23日

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格