android.widget.ImageView#getRotation ( )源码实例Demo

下面列出了android.widget.ImageView#getRotation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ExpandableRecyclerView   文件: SingleRvFragment.java
@Override
public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG,
             "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser);

    if (pvh == null) return;
    ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    float currRotate = arrow.getRotation();
    float rotate = 360;
    //未展开完全并且当前旋转角度小于180,逆转回去
    if (currRotate < 180) {
        rotate = 0;
    }
    if (pendingCause) {
        arrow.setRotation(rotate);
    } else {
        arrow.animate()
             .rotation(rotate)
             .setDuration(mItemAnimator.getRemoveDuration() + 180)
             .start();
    }
}
 
@Override
public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser);
    if (pvh == null) return;
    ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    float currRotate = arrow.getRotation();
    //重置为从0开始旋转
    if (currRotate == 360) {
        arrow.setRotation(0);
    }
    if (pendingCause) {
        arrow.setRotation(180);
    } else {
        arrow.animate()
             .rotation(180)
             .setDuration(mItemAnimator.getAddDuration() + 180)
             .start();
    }
}
 
@Override
public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG,
            "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser);

    if (pvh == null) return;
    final ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    final float currRotate = arrow.getRotation();
    float rotate = 360;
    //未展开完全并且当前旋转角度小于180,逆转回去
    if (currRotate < 180) {
        rotate = 0;
    }
    if (pendingCause) {
        arrow.setRotation(rotate);
    } else {
        arrow.animate().rotation(rotate)
                .setDuration(mItemAnimator.getRemoveDuration() + 180).start();
    }
}
 
源代码4 项目: ExpandableRecyclerView   文件: SingleRvFragment.java
@Override
public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser);
    if (pvh == null) return;
    ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    float currRotate = arrow.getRotation();
    //重置为从0开始旋转
    if (currRotate == 360) {
        arrow.setRotation(0);
    }
    if (pendingCause) {
        arrow.setRotation(180);
    } else {
        arrow.animate()
             .rotation(180)
             .setDuration(mItemAnimator.getAddDuration() + 180)
             .start();
    }

    //            if (byUser) {
    //                int scrollToPos =
    //                        pvh.getAdapterPosition() + ((MyParent) pvh.getParent()).getChildCount();
    //                rv.scrollToPosition(scrollToPos);
    //            }
}
 
源代码5 项目: android   文件: CompassView.java
/**
 * Resets compass to point to North.
 */
public void reset() {
  final ImageView image = (ImageView) findViewById(getImageId());
  if (image != null) {
    float newRotation = (image.getRotation() < 180) ? 0 : 360;
    image.animate().setDuration(ROTATION_ANIMATION_DURATION_MILLIS).rotation(newRotation);
    animate().setDuration(FADE_OUT_ANIMATION_DURATION_MILLIS).alpha(0f)
      .setStartDelay(ROTATION_ANIMATION_DURATION_MILLIS);
  }
}
 
public void startAnimation(View view) {
	float dest = 0;
	final ImageView aniView = (ImageView) findViewById(R.id.imageView1);

	switch (view.getId()) {
	case R.id.Button01:

		dest = 360;
		if (aniView.getRotation() == 360) {
			dest = 0;
		}
		// ObjectAnimator animation1 = ObjectAnimator.ofFloat(aniView,
		// "rotation", dest);
		// animation1.setDuration(2000);
		// animation1.start();

		aniView.animate().rotation(dest).setDuration(1000).scaleX(2)
				.scaleY(2).withEndAction(new Runnable() {

					@Override
					public void run() {
						//
						aniView.animate()
								.rotationXBy(100)
								.rotation(
										Math.abs(360 - aniView
												.getRotation()))
								.scaleX(0.4F).scaleY(0.4F)
								.setDuration(1000);
					}
				});

		// Show how to load an animation from XML
		// Animation animation1 = AnimationUtils.loadAnimation(this,
		// R.anim.myanimation);
		// animation1.setAnimationListener(this);
		// animatedView1.startAnimation(animation1);
		break;

	case R.id.Button02:
		// Shows how to define a animation via code
		// Also use an Interpolator (BounceInterpolator)
		Paint paint = new Paint();
		TextView aniTextView = (TextView) findViewById(R.id.textView1);
		float measureTextCenter = paint.measureText(aniTextView.getText()
				.toString());
		dest = 0 - measureTextCenter;
		if (aniTextView.getX() < 0) {
			dest = 0;
		}
		ObjectAnimator animation2 = ObjectAnimator.ofFloat(aniTextView,
				"x", dest);
		animation2.setDuration(2000);
		animation2.start();
		break;

	case R.id.Button03:
		// Demonstrate fading and adding an AnimationListener

		dest = 1;
		if (aniView.getAlpha() > 0) {
			dest = 0;
		}
		ObjectAnimator animation3 = ObjectAnimator.ofFloat(aniView,
				"alpha", dest);
		animation3.setDuration(2000);
		animation3.start();
		break;

	case R.id.Button04:

		ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView, "alpha",
				0f);
		fadeOut.setDuration(2000);
		ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,
				"translationX", -500f, 0f);
		mover.setDuration(2000);
		ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView, "alpha",
				0f, 1f);
		fadeIn.setDuration(2000);
		AnimatorSet animatorSet = new AnimatorSet();

		animatorSet.play(mover).with(fadeIn).after(fadeOut);
		animatorSet.start();
		break;

	default:
		break;
	}

}
 
public void startAnimation(View view) {
	float dest = 0;
	final ImageView aniView = (ImageView) findViewById(R.id.imageView1);

	switch (view.getId()) {
	case R.id.Button01:

		dest = 360;
		if (aniView.getRotation() == 360) {
			dest = 0;
		}
		// ObjectAnimator animation1 = ObjectAnimator.ofFloat(aniView,
		// "rotation", dest);
		// animation1.setDuration(2000);
		// animation1.start();

		aniView.animate().rotation(dest).setDuration(1000).scaleX(2)
				.scaleY(2).withEndAction(new Runnable() {

					@Override
					public void run() {
						//
						aniView.animate()
								.rotationXBy(100)
								.rotation(
										Math.abs(360 - aniView
												.getRotation()))
								.scaleX(0.4F).scaleY(0.4F)
								.setDuration(1000);
					}
				});

		// Show how to load an animation from XML
		// Animation animation1 = AnimationUtils.loadAnimation(this,
		// R.anim.myanimation);
		// animation1.setAnimationListener(this);
		// animatedView1.startAnimation(animation1);
		break;

	case R.id.Button02:
		// Shows how to define a animation via code
		// Also use an Interpolator (BounceInterpolator)
		Paint paint = new Paint();
		TextView aniTextView = (TextView) findViewById(R.id.textView1);
		float measureTextCenter = paint.measureText(aniTextView.getText()
				.toString());
		dest = 0 - measureTextCenter;
		if (aniTextView.getX() < 0) {
			dest = 0;
		}
		ObjectAnimator animation2 = ObjectAnimator.ofFloat(aniTextView,
				"x", dest);
		animation2.setDuration(2000);
		animation2.start();
		break;

	case R.id.Button03:
		// Demonstrate fading and adding an AnimationListener

		dest = 1;
		if (aniView.getAlpha() > 0) {
			dest = 0;
		}
		ObjectAnimator animation3 = ObjectAnimator.ofFloat(aniView,
				"alpha", dest);
		animation3.setDuration(2000);
		animation3.start();
		break;

	case R.id.Button04:

		ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView, "alpha",
				0f);
		fadeOut.setDuration(2000);
		ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,
				"translationX", -500f, 0f);
		mover.setDuration(2000);
		ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView, "alpha",
				0f, 1f);
		fadeIn.setDuration(2000);
		AnimatorSet animatorSet = new AnimatorSet();

		animatorSet.play(mover).with(fadeIn).after(fadeOut);
		animatorSet.start();
		break;

	default:
		break;
	}

}
 
public void startAnimation(View view) {
	float dest = 0;
	final ImageView aniView = (ImageView) findViewById(R.id.imageView1);

	switch (view.getId()) {
	case R.id.Button01:

		dest = 360;
		if (aniView.getRotation() == 360) {
			dest = 0;
		}
		// ObjectAnimator animation1 = ObjectAnimator.ofFloat(aniView,
		// "rotation", dest);
		// animation1.setDuration(2000);
		// animation1.start();

		aniView.animate().rotation(dest).setDuration(1000).scaleX(2)
				.scaleY(2).withEndAction(new Runnable() {

					@Override
					public void run() {
						//
						aniView.animate()
								.rotationXBy(100)
								.rotation(
										Math.abs(360 - aniView
												.getRotation()))
								.scaleX(0.4F).scaleY(0.4F)
								.setDuration(1000);
					}
				});

		// Show how to load an animation from XML
		// Animation animation1 = AnimationUtils.loadAnimation(this,
		// R.anim.myanimation);
		// animation1.setAnimationListener(this);
		// animatedView1.startAnimation(animation1);
		break;

	case R.id.Button02:
		// Shows how to define a animation via code
		// Also use an Interpolator (BounceInterpolator)
		Paint paint = new Paint();
		TextView aniTextView = (TextView) findViewById(R.id.textView1);
		float measureTextCenter = paint.measureText(aniTextView.getText()
				.toString());
		dest = 0 - measureTextCenter;
		if (aniTextView.getX() < 0) {
			dest = 0;
		}
		ObjectAnimator animation2 = ObjectAnimator.ofFloat(aniTextView,
				"x", dest);
		animation2.setDuration(2000);
		animation2.start();
		break;

	case R.id.Button03:
		// Demonstrate fading and adding an AnimationListener

		dest = 1;
		if (aniView.getAlpha() > 0) {
			dest = 0;
		}
		ObjectAnimator animation3 = ObjectAnimator.ofFloat(aniView,
				"alpha", dest);
		animation3.setDuration(2000);
		animation3.start();
		break;

	case R.id.Button04:

		ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView, "alpha",
				0f);
		fadeOut.setDuration(2000);
		ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,
				"translationX", -500f, 0f);
		mover.setDuration(2000);
		ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView, "alpha",
				0f, 1f);
		fadeIn.setDuration(2000);
		AnimatorSet animatorSet = new AnimatorSet();

		animatorSet.play(mover).with(fadeIn).after(fadeOut);
		animatorSet.start();
		break;

	default:
		break;
	}

}