How to move an image from left to right in android

后端 未结 4 1421
余生分开走
余生分开走 2020-11-30 00:56

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?

Thanks.

4条回答
  •  抹茶落季
    2020-11-30 01:10

        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);
    

    is one way of doing it.

提交回复
热议问题