小编Pra*_*dey的帖子

Android通过动画不断移动背景

我想要做的是水平移动背景并让它无限重复.

我尝试使用ImageSwitcher动画来产生这种效果,但无法使其正常工作.这是我到目前为止的代码

public class MainActivity extends AppCompatActivity implements ViewSwitcher.ViewFactory {

    private Animation animSlide;
    private ImageSwitcher image;
    private ImageView imagePop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        image = (ImageSwitcher) findViewById(R.id.image_switcher);

        image.setFactory(this);
        image.setImageResource(R.drawable.zc06);
        Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
        in.setDuration(10000);
        Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
        out.setDuration(10000);
        image.setInAnimation(in);
        image.setOutAnimation(out);
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        image.setImageResource(R.drawable.zc06);
                    }
                });
            }

        }, 0, 10000);

        Animation mZoomInAnimation = …
Run Code Online (Sandbox Code Playgroud)

java android android-animation

18
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

android-animation ×1

java ×1