今天看到RotateAnimation的一个构造方法,final Animation rotateAnimation = new RotateAnimation(90f, 360f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
一下是官方文档的详细解释:
android.view.animation..RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
Constructor to use when building a RotateAnimation from code
- Parameters:
- fromDegrees Rotation offset to apply at the start of the animation.动画开始时的角度。但是第一次点击开始动画,图片不会一开始就以90度的位置摆放,而是在开始动画的时候,才会从图片90度摆放的位置开发旋转。
- toDegrees Rotation offset to apply at the end of the animation.动画结束时的角度。
- pivotXType Specifies how pivotXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.设置类型。转动的点是以屏幕左上方开始还是别的方式。RELATIVE_TO_SELF,相对自己为标准;RELATIVE_TO_PARENT,相对父组件为标准;ABSOLUTE,表示绝对位置(那么对应的值应该是具体的坐标值,比如100到300,指绝对的屏幕像素单位)。
- pivotXValue The X coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the left edge. This value can either be an absolute number if pivotXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.针对上面的类型具体的值。(0是左边缘,取值在0-1之间,1代表100%)
- pivotYType Specifies how pivotYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
- pivotYValue The Y coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the top edge. This value can either be an absolute number if pivotYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
- int firstPosition = postsListView.getFirstVisiblePosition();
- int visiblePosition = postsListView.getChildCount();
- for (int i = firstPosition; i < visiblePosition + firstPosition; i++) {
- if (i == 0) { //指定了改变的具体Item,如果所有可视的Item都需要改变则不需要这个if判断
- View view = (View) postsListView.getChildAt(firstPosition);
- PostsTopicAdapterHolder topicHolder = (PostsTopicAdapterHolder) view.getTag();
- ImageButton topicFavoriteBtn = topicHolder.getTopicFavoriteBtn();
- if (topicModel.getIsFavor() == PostsApiConstant.TOPIC_UNFAVOR) {
- topicFavoriteBtn.setBackgroundResource(resource.getDrawableId("mc_forum_icon28"));
- } else {
- topicFavoriteBtn.setBackgroundResource(resource.getDrawableId("mc_forum_icon27"));
- }
- }
- }