After linearlayout rotation, onclick events do not change position after rotation

I have a vertical linearlayout with three clickableviewviews within a linearlayout. When I rotate linearlayout 90 degrees using simple animation, a problem arises. Image images are correctly rotated, but onclick events for images do not rotate along with linearlayout and remain in their original position until the animation.

Below is my main Java code

westplayer = (LinearLayout) findViewById(R.id.linearLayout_west); // Create an animation instance Animation an = new RotateAnimation(0.0f, 180.0f, 32, 180); // Set the animation parameters an.setDuration(0); // duration in ms an.setRepeatCount(0); // -1 = infinite repeated an.setRepeatMode(Animation.REVERSE); // reverses each repeat an.setFillAfter(true); // keep rotation after animation // Apply animation to linearlayout westplayer.setAnimation(an); 

The code above handles part of the animation. The following code follows the animation and is redefined to update the layout positions, but does not work for me.

  // Update Layout int top=westplayer.getTop(); int bottom=westplayer.getBottom(); int left=westplayer.getLeft(); int right=westplayer.getRight(); westplayer.layout(left, top , right, bottom ); 

xml is as follows:

  <LinearLayout android:id="@+id/linearLayout_west" android:layout_width="42dp" android:layout_height="250dp" android:layout_alignParentLeft="true" android:layout_below="@+id/linearLayout_north" android:duplicateParentState="false" android:gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/imageViewW1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/spades_14" /> <ImageView android:id="@+id/imageViewW2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/spades_14" android:layout_marginTop="-15dp" /> <ImageView android:id="@+id/imageViewW3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/spades_14" android:layout_marginTop="-15dp" /> </LinearLayout> 

I have update layout code from this , and also found another solution that I also tried this and there are still no positive results. I need this for API 10 to work. Any help is much appreciated

+4
source share
2 answers

Yes, you got the expected result.

Since the animation in android is only trying to apply the transformation matrix to the bitmap, it does not change the position and size of the view.

So, after your animation, although you setFillAfter(true) so that the view looks rotated, but in fact the view is still in one place and does not move a bit.

0
source

The problem you are facing is that you are using Tween animations. The view will rotate, and only the visible part will move. But ImageView positions will remain the same as defined in the layout. This is why the clickable area remains the same.

To redefine the position, in accordance with the animation you will have to use Property Animation , for example, ObjectAnimator or ValueAnimator . With this, the properties defined in xml will be updated. Clickable areas now move with the views.

0
source

Source: https://habr.com/ru/post/1500093/


All Articles