如何在android中从左到右移动图像 [英] How to move an image from left to right in android

查看:37
本文介绍了如何在android中从左到右移动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 android 动画在模拟器上从左到右翻译图像.我是 android 动画的新手.我怎么能那样做?

I'd like to translate an image from left to right on emulator using android animation. I'm new to android animation. How could I do that?

谢谢.

推荐答案

    ll = new LinearLayout(this);
    ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);

    tv = new TextView(this);
    tv.setText("Animation");

    moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);
    moveLefttoRight.setDuration(1000);
    moveLefttoRight.setFillAfter(true);

    button = new Button(this);
    button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    button.setText("PressMe");
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            tv.startAnimation(moveLefttoRight);
        }

    });

    ll.addView(tv);
    ll.addView(button);
    setContentView(ll);

是一种方法.

这篇关于如何在android中从左到右移动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆