I have a image with a few buttons on the view. One of the buttons moves the image down. It moves the image down by adding 1 px to the top margin. Here is the code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
final ImageView image = (ImageView) findViewById(R.id.image1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ViewGroup.MarginLayoutParams) image.getLayoutParams()).topMargin += 1;
image.requestLayout();
}
});
}
Now, i want to be able to rotate the image. Just like the code i have now, I want a button, when the button is pressed the image will rotate. But how can i do this?