Nurzhan Nogerbek
Nurzhan Nogerbek

Reputation: 5246

Rotate ImageView in Sliding Up Panel

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!

Upvotes: 1

Views: 2142

Answers (2)

kumar kundan
kumar kundan

Reputation: 2057

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);

            }

Upvotes: 3

JakeP
JakeP

Reputation: 1756

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);

}

Upvotes: 3

Related Questions