I have a background and I just want to repeat my background From :
Upward to Downward Direction
Downward to Upward Direction
Right to Left Direction
Left to Right Direction
What should I do for it?
I have a background and I just want to repeat my background From :
Upward to Downward Direction
Downward to Upward Direction
Right to Left Direction
Left to Right Direction
What should I do for it?
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;
}
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);
}
});
}
}