How can I rotate the item views in the RecyclerView?
<p>I'm building an app and it has an activity that is fixed in landscape mode. When the user rotates the screen, instead of destroying and re-creating the activity, it will rotate the views and stay in landscape. </p>

<p>I made all other views animated by extending RotateAnimation class but I have no idea how to rotate icons in the RecyclerView. I tried to pass the ViewHolder inside of my adapter class to the animation class but it didn't work. </p>

<p>Here is my code. </p>

<p><strong>MainActivity.java</strong></p>

<pre><code>private void prepOrientationHandler(){
        orientationHandler = new OrientationHandler(this, getRotation());
        orientationHandler.setViews(myIcon);
    }
</code></pre>

<p><strong>ViewRotationAnim.java</strong></p>

<pre><code>public class ViewRotationAnim extends RotateAnimation {

float mFrom;
float mTo;
float mPivotX;
float mPivotY;
float mPivotXValue;
float mPivotYValue;

public ViewRotationAnim(float mFrom, float mTo, float mPivotX, float mPivotY) {
    super(mFrom, mTo, Animation.RELATIVE_TO_SELF, mPivotX, Animation.RELATIVE_TO_SELF, mPivotY);
    this.mFrom = mFrom;
    this.mTo = mTo;
    this.mPivotX = mPivotX;
    this.mPivotY = mPivotY;
    this.mPivotXValue = mPivotX;
    this.mPivotYValue = mPivotY;
}

public void setFromTo(float mFrom, float mTo) {
    this.mFrom = mFrom;
    this.mTo = mTo;
}

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
    mPivotX = resolveSize(Animation.RELATIVE_TO_SELF, mPivotXValue, width, parentWidth);
    mPivotY = resolveSize(Animation.RELATIVE_TO_SELF, mPivotYValue, height, parentHeight);
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    float degrees = 0;
    if (mFrom == 0 &amp;&amp; mTo == 270) {
        degrees = 360 - (90 * interpolatedTime);
    } else if (mFrom == 270 &amp;&amp; mTo == 0) {
        degrees = 270 + (90 * interpolatedTime);
    } else {
        degrees = mFrom + ((mTo - mFrom) * interpolatedTime);
    }
    float scale = getScaleFactor();
    if (mPivotX == 0.0f &amp;&amp; mPivotY == 0.0f) {
        t.getMatrix().setRotate(degrees);
    } else {
        t.getMatrix().setRotate(degrees, mPivotX * scale, mPivotY * scale);
    }
}
</code></pre>

<p>}</p>

<p><strong>OrientationHandler.java</strong></p>

<pre><code>public class OrientationHandler extends OrientationEventListener {
final int ROTATION_0 = 0;
final int ROTATION_90 = 90;
final int ROTATION_180 = 180;
final int ROTATION_270 = 270;

private int rotation;
private int currentViewRotation = 0;
private ImageView myIcon;
private ViewRotationAnim rotationAnimForIcons;

public OrientationHandler(Context context, int rotation) {
    super(context);
    rotationAnimForIcons = new ViewRotationAnim(0, 0, 0.5f, 0.5f);
    rotationAnimForIcons.setDuration(500);
    rotationAnimForIcons.setFillAfter(true);
    this.rotation = rotation;
}

public void setViews(View... views) {
    myIcon = (ImageView) views[0];
}

private void rotateView() {
    myIcon.startAnimation(rotationAnimForIcons);
}

@Override
public void onOrientationChanged(int orientation) {
    if ((orientation &lt; 35 || orientation &gt; 325) &amp;&amp; rotation != ROTATION_0) {
        rotationAnimForIcons.setFromTo(currentViewRotation, ROTATION_270);
        rotateViews();
        rotation = ROTATION_0;
        currentViewRotation = ROTATION_270;
    } else if (orientation &gt; 145 &amp;&amp; orientation &lt; 215 &amp;&amp; rotation != ROTATION_180) {
        rotationAnimForIcons.setFromTo(currentViewRotation, ROTATION_90);
        rotateViews();
        rotation = ROTATION_180;
        currentViewRotation = ROTATION_90;
    } else if (orientation &gt; 55 &amp;&amp; orientation &lt; 125 &amp;&amp; rotation != ROTATION_270) {
        rotationAnimForIcons.setFromTo(currentViewRotation, ROTATION_180);
        rotateViews();
        rotation = ROTATION_270;
        currentViewRotation = ROTATION_180;
    } else if (orientation &gt; 235 &amp;&amp; orientation &lt; 305 &amp;&amp; rotation != ROTATION_90) {
        rotationAnimForIcons.setFromTo(currentViewRotation, ROTATION_0);
        rotateViews();
        rotation = ROTATION_90;
        currentViewRotation = ROTATION_0;
    }
}
</code></pre>

<p>}</p>

<p><strong>IconListAdapter.java</strong></p>

<pre><code>public class IconListAdapter extends RecyclerView.Adapter&lt;IconListAdapter.ViewHolder&gt; {

    private Context mContext;
    private RealmResults&lt;MyIcon&gt; mIcons;

    public IconListAdapter(Context mContext, RealmResults&lt;MyIcon&gt; mIcons) {
        this.mContext = mContext;
        this.mIcons = mIcons;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView mIconView;

        public ViewHolder(View itemView) {
            super(itemView);
            this.mIconView = (ImageView) itemView.findViewById(R.id.main_activity_list_item);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.video_sound_list_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        MyIcon currentIcon = mIcons.get(position);
        holder.mIconView.setImageResource(currentIcon.getIconResource());
    }

    @Override
    public int getItemCount() {
        return mIcons.size();
    }
}
</code></pre>

<p>This code works perfectly for normal views. But I don't know where to start to rotate items in my RecyclerView. 
Any ideas? </p>