[英]Android: How to only rotate the drawable part of an imageView?
I have an ImageView object where both its Background and drawable attributes are set. 我有一个ImageView对象,其中设置了Background和drawable属性。 I need to animate the drawable part of the ImageView while the background stay still. 我需要在背景保持静止的同时为ImageView的可绘制部分设置动画。
I can't find a way to do it... 我找不到办法做到这一点......
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:drawable="@drawable/ic_popup_sync_1"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1200"
android:toDegrees="360" />
imageView.startAnimation(AnimationUtils.loadAnimation(context, animId)); imageView.startAnimation(AnimationUtils.loadAnimation(context,animId));
Both the drawable and the background are rotating at the same time... drawable和background都在同时旋转......
Set the background to a separate layout that sits behind the ImageView
. 将背景设置为位于ImageView
后面的单独布局。 Put both into a RelativeLayout
where the background View
is aligned to the ImageView
by left, right, top, and bottom so that the background stays within the image's bounds. 将两者放入RelativeLayout
,其中背景View
通过左,右,顶部和底部与ImageView
对齐,以便背景保持在图像的边界内。 Then you can rotate the image freely. 然后您可以自由旋转图像。
EDIT: 编辑:
Better yet, but the ImageView
inside a layout and set the layout to WRAP_CONTENT
. 更好的是,但布局中的ImageView
并将布局设置为WRAP_CONTENT
。 Set the layout's background to your background image. 将布局的背景设置为背景图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.