0

I have a background and I just want to repeat my background From :

  1. Upward to Downward Direction

  2. Downward to Upward Direction

  3. Right to Left Direction

  4. Left to Right Direction

What should I do for it?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Akarsh M
  • 1,629
  • 2
  • 24
  • 47

2 Answers2

0

use touch event , just apply the setTranslationX and setTranslationY. it will rotate the background image.. write listener code image object like setontouchlistener touch event method

 float previousX = 0,previousY = 0;

 switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
             previousX = ev.getX();
             previousY = ev.getY();
            break;
    case MotionEvent.ACTION_MOVE:

    final float deltaX = ev.getX() - previousX;
            final float deltaY = ev.getY() - previousY;
            objectName.setTranslationX(this.getTranslationX() + deltaX);
            objectName.setTranslationY(this.getTranslationY() + deltaY);

            previousX = ev.getX();
            previousY = ev.getY();
            break;
}
harikrishnan
  • 1,985
  • 4
  • 32
  • 63
  • thanks for the reply but I want to rotate background without any touch listener . It's like continuous rotation of the backgroud – Akarsh M Jul 11 '13 at 13:20
  • create anim folder in res folder in android. and write rotation animation code in that anim->anim.xml file. and call it via main activity. before give that image xml code like android:rotation=360 degrees.. – harikrishnan Jul 11 '13 at 13:27
  • I m using this thing for the cocos2d-android , I cant do this thing still – Akarsh M Jul 11 '13 at 13:30
  • just refer this link..http://stackoverflow.com/questions/3760381/rotating-image-animation-list-or-animated-rotate-android – harikrishnan Jul 11 '13 at 13:30
0

without touch listener..its for simple rotate animation in android...

Once you have created a new Android project, create a folder named anim in res and a file named rotator.xml inside res/anim.

 <?xml version="1.0" encoding="utf-8"?>
 <rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:toYScale="0.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="4000"
 />

Hope the code is pretty self explanatory. Here one complete rotation will be completed in 4000ms (4 seconds). Now add a PNG image that you want to rotate into your drawable folder. Then open res/main.xml, after removing the default textView in the layout, add an ImageView and Button into the layout. Set the src property of the ImageView as your filename of the added image, for example

android:src="@drawable/myimg"

Ok, lets edit the main class. In the onClick() for the button, add the necessary code for running the animation. Check the following code.

public class AnimationActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener()    {
            @Override
            public void onClick(View arg0) {
                final ImageView myImage = (ImageView)findViewById(R.id.imageView1);
                final Animation
             myRotation =  AnimationUtils.loadAnimation(getApplicationContext(),
     R.anim.rotator);
                myImage.startAnimation(myRotation);
            }
        });
    }
   }
harikrishnan
  • 1,985
  • 4
  • 32
  • 63