musica musica - 3 months ago 28
Android Question

Rotate image left/right by an angle on button click

Using picasso-transformations library for Image editing.There are two separate buttons for left rotation and right rotation.On button click, the Image rotates only once. I want to rotate Image on every button click to its respective direction.

recyclerView.addOnItemTouchListener(new RecyclerClick(act, recyclerView, new RecyclerClickListener() {
@Override
public void onClick(View view, final int position) {
switch (position) {
case 0:
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(90f)
.into(photo);
break;
case 1:
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(90f)
.into(photo);
break;
}
}

Answer

Maybe instance variables helps.

like this:

recyclerView.addOnItemTouchListener(new RecyclerClick(act, recyclerView, new RecyclerClickListener() {

    int rotate = 0;

    @Override
    public void onClick(View view, final int position) {
        switch (position) {
            case 0:
                rotate += 90f
                break;
            case 1:
                rotate -= 90f;
                break;
        }
        Picasso.with(act)
                .load(selectedPhotoUri)
                .rotate(rotate)
                .into(photo);
    }
}));
Comments