Rotate a layout like a PENDULUM [closed]

2019-02-27 12:14发布

问题:

Can I move a inflated layout or dialog or(another way) etc like a PENDULUM. Inflated layout contain some image view and text view . Is it possible through animation or not

thanks in advance

回答1:

You can use a RotateAnimation and assign it to your parent view.

However, to get a swing effect (like a pendulum) you need to provide proper values for pivot and degrees.

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="-135"
android:toDegrees="-45" android:drawable="@drawable/imagefile_to_rotate"
android:repeatCount="infinite" />

In your case you need a layer-list drawable to combine an image with a text. See this. http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList

However, you can use a Drawable and not a View in LayerList. So the thing is you cannot use a View but will have to create a custom Drawable.