1

In my android application I used umano`s sliding up panel (Click here)

I am tring to twist(rotate) ImageView as in the picture below. The changes of ImageView depends on how far panel opened. Is it possible to twist(rotate) ImageView by sliding of panel?

Here is the method in which slideOffset shows how much panel was opened but I dont know how to correctly use it in my case to rotate the ImageView. By the way I used slideOffset for change the color gradually by sliding panel.

@Override
public void onPanelSlide(View panel, float slideOffset) {
       Log.i(TAG, "onPanelSlide, offset " + slideOffset);

       //Here is the code which change titleBar color gradually
       titleBar.setBackgroundColor((int) colorEvaluator.evaluate(slideOffset, Color.parseColor("#03A9F4"), Color.parseColor("#F44336")));

}

enter image description here

Thanks for any help!

Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193

2 Answers2

3

It should be possible.

What you need to do is check the initial and final value of slideOffset - I'd expect it to be 0 at the very beginning and then probably something like the height of the screen.

If that's the case, then you should be able to calculate the angle of the rotation using a simple proportion equation:

@Override
public void onPanelSlide(View panel, float slideOffset) {
       Log.i(TAG, "onPanelSlide, offset " + slideOffset);

       //Here is the code which change titleBar color gradually
       titleBar.setBackgroundColor((int) colorEvaluator.evaluate(slideOffset, Color.parseColor("#03A9F4"), Color.parseColor("#F44336")));

    float angle = slideOffset * 180 / slideOffsetMax;
    imageView.setRotation(angle);

}
JakeP
  • 1,736
  • 4
  • 23
  • 31
  • Hello JakeP! How are you? Unfortunatly it didnt work. ImageView didn`t change. I tested with different values of slideOffsetMax =( – Nurzhan Nogerbek Feb 22 '15 at 15:57
  • Try setting an arbitrary value, say 90, as angle and see if the image gets rotated at all. – JakeP Feb 22 '15 at 16:25
  • I used now this: float angle = 90; mImageView.setRotation(angle); but it rotate ImageView instantly and only in one way but rotate must be gradually depends on how far panel was opened as i said. Another what I forgot to ask is to return the ImageView to first position when user will close panel. Do you have any ideas about that? – Nurzhan Nogerbek Feb 22 '15 at 18:33
  • You should be able to rotate the ImageView to its initial position by using setRotation(0) on it. As for the problem with rotating, it seems something's wrong with the slideOffsetMax you chose. It should be the highest value your slideOffset can take so that the angle equals 180 at the top of the screen. Does that make sense? – JakeP Feb 22 '15 at 19:07
3

Try this , it will definitely rotate your image as per your requirement :-

@Override
            public void onPanelSlide(View panel, float slideOffset) {

                Log.i(TAG, "onPanelSlide, offset " + slideOffset);

                float angle = slideOffset * 180;
                mImageViewArrow.setRotation(angle);

            }
kumar kundan
  • 2,027
  • 1
  • 27
  • 41