下面列出了android.view.animation.RotateAnimation#setRepeatCount() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
super(context, mode, scrollDirection, attrs);
mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);
mHeaderImage.setScaleType(ScaleType.MATRIX);
mHeaderImageMatrix = new Matrix();
mHeaderImage.setImageMatrix(mHeaderImageMatrix);
mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
mRotateAnimation.setRepeatCount(Animation.INFINITE);
mRotateAnimation.setRepeatMode(Animation.RESTART);
}
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
super(context, mode, scrollDirection, attrs);
mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);
mHeaderImage.setScaleType(ScaleType.MATRIX);
mHeaderImageMatrix = new Matrix();
mHeaderImage.setImageMatrix(mHeaderImageMatrix);
mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
mRotateAnimation.setRepeatCount(Animation.INFINITE);
mRotateAnimation.setRepeatMode(Animation.RESTART);
}
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
super(context, mode, scrollDirection, attrs);
mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);
mHeaderImage.setScaleType(ScaleType.MATRIX);
mHeaderImageMatrix = new Matrix();
mHeaderImage.setImageMatrix(mHeaderImageMatrix);
mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
mRotateAnimation.setRepeatCount(Animation.INFINITE);
mRotateAnimation.setRepeatMode(Animation.RESTART);
}
public void refresh(boolean start)
{
if (mSyncButton == null) {
return;
}
if (start) {
RotateAnimation rotateAnimation = new RotateAnimation(
0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setFillAfter(true);
rotateAnimation.setDuration(700);
rotateAnimation.setRepeatCount(500);
mSyncButton.startAnimation(rotateAnimation);
} else {
mSyncButton.clearAnimation();
}
}
private void initView(Context context, AttributeSet attrs) {
CircleProgressDrawable drawable = new CircleProgressDrawable();
if (null != attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, 0, 0);
int arcColor = a.getColor(R.styleable.CircleProgressBar_color_arc, 0);
int bgColor = a.getColor(R.styleable.CircleProgressBar_color_background, 0);
float strokeWidth = a.getDimension(R.styleable.CircleProgressBar_stroke_width, 5.f);
drawable.setStrokeWidth(strokeWidth);
drawable.setArcColor(arcColor);
drawable.setBackgroundColor(bgColor);
a.recycle();
}
setImageDrawable(drawable);
mAnimation = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
mAnimation.setDuration(800);
mAnimation.setInterpolator(new LinearInterpolator());
mAnimation.setRepeatCount(-1);
mAnimation.setRepeatMode(RotateAnimation.RESTART);
startAnimation(mAnimation);
}
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
super(context, mode, scrollDirection, attrs);
mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);
mHeaderImage.setScaleType(ScaleType.MATRIX);
mHeaderImageMatrix = new Matrix();
mHeaderImage.setImageMatrix(mHeaderImageMatrix);
mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
mRotateAnimation.setRepeatCount(Animation.INFINITE);
mRotateAnimation.setRepeatMode(Animation.RESTART);
}
private void initView(Context context) {
View.inflate(context, R.layout.view_ptr_footer, this);
loadingView = (ImageView) findViewById(R.id.iv_loading);
rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(600);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setRepeatCount(Animation.INFINITE);
setVisibility(GONE);
}
@Override
public void show() {
super.show();
RotateAnimation anim = new RotateAnimation(0.0f, 359.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
rotatingImageView.setAnimation(anim);
rotatingImageView.startAnimation(anim);
}
public static void rotateDown(View view) {
RotateAnimation rotate = new RotateAnimation(180f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
LinearInterpolator lin = new LinearInterpolator();
rotate.setInterpolator(lin);
rotate.setDuration(200);
rotate.setRepeatCount(0);
rotate.setFillAfter(true);
rotate.setStartOffset(10);
view.startAnimation(rotate);
}
/**
* Start the video loading animation.
*/
private void startLoading() {
mIsLoading = true;
mOverlayProgress.setVisibility(View.INVISIBLE);
AnimationSet anim = new AnimationSet(true);
RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(800);
rotate.setInterpolator(new DecelerateInterpolator());
rotate.setRepeatCount(RotateAnimation.INFINITE);
anim.addAnimation(rotate);
mLoading.startAnimation(anim);
}
private void initAnimation() {
bindingView.llLoading.setVisibility(View.VISIBLE);
animation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(3000);//设置动画持续时间
animation.setInterpolator(new LinearInterpolator());//不停顿
animation.setRepeatMode(ValueAnimator.RESTART);//重新从头执行
animation.setRepeatCount(ValueAnimator.INFINITE);//设置重复次数
bindingView.ivLoading.setAnimation(animation);
animation.startNow();
}
private Animation getRotateAnimation() {
RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f,
getWidth() / 2, getHeight() / 2);
rotateAnimation.setDuration(2000);
rotateAnimation.setRepeatCount(1);
rotateAnimation.setFillAfter(true);
rotateAnimation.setFillBefore(false);
rotateAnimation.setRepeatMode(Animation.REVERSE);
return rotateAnimation;
}
public void startProgress(){
if (mRefreshButton.getAnimation() != null)
return;
RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(500);
rotateAnimation.setFillAfter(false);
rotateAnimation.setRepeatCount(-1);
rotateAnimation.setRepeatMode(Animation.RESTART);
rotateAnimation.setInterpolator(new LinearInterpolator());
mRefreshButton.startAnimation(rotateAnimation);
}
private ViewLoading(Context context , String content , boolean canNotCancel) {
super(context, R.style.Loading);
this.canNotCancel = canNotCancel;
// 加载布局
if(content!=null && content.length()>0){
setContentView(R.layout.layout_dialog_loading);
TextView message = findViewById(R.id.message);
message.setText(content);
}else {
setContentView(R.layout.layout_dialog_loaded);
}
ImageView progressImageView = findViewById(R.id.iv_image);
//创建旋转动画
animation = new RotateAnimation(0f, 360f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);
//动画的重复次数
animation.setRepeatCount(10);
//设置为true,动画转化结束后被应用
animation.setFillAfter(true);
//开始动画
progressImageView.startAnimation(animation);
// 设置Dialog参数
Window window = getWindow();
if(window!=null){
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.CENTER;
window.setAttributes(params);
}
}
private void e()
{
A = new RotateAnimation(-5F, 5F, 0, Utils.convertDpToPixel(16F, getActivity()), 0, Utils.convertDpToPixel(33F, getActivity()));
A.setAnimationListener(new bR(this));
A.setDuration(50L);
A.setRepeatCount(20);
A.setInterpolator(new AccelerateDecelerateInterpolator());
A.setRepeatMode(2);
}
/**
* 旋转
* @param view
* @param durationMillis
* @param delayMillis
*/
public void viewRotateForver(View view, long durationMillis, long delayMillis)
{
view.measure(0, 0);
float x=view.getMeasuredHeight();
float y=view.getMeasuredWidth();
RotateAnimation animation=new RotateAnimation(0,359,x/2,y/2);
animation.setFillAfter(true);
animation.setRepeatCount(-1);
animation.setDuration(1500);
LinearInterpolator lin = new LinearInterpolator();
animation.setInterpolator(lin);
view.startAnimation(animation);
}
public static RotateAnimation initRotateAnimation(long duration,
int fromAngle, int toAngle,
boolean isFillAfter, int repeatCount) {
RotateAnimation mLoadingRotateAnimation = new RotateAnimation(fromAngle, toAngle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
LinearInterpolator lirInterpolator = new LinearInterpolator();
mLoadingRotateAnimation.setInterpolator(lirInterpolator);
mLoadingRotateAnimation.setDuration(duration);
mLoadingRotateAnimation.setFillAfter(isFillAfter);
mLoadingRotateAnimation.setRepeatCount(repeatCount);
mLoadingRotateAnimation.setRepeatMode(Animation.RESTART);
return mLoadingRotateAnimation;
}
public RotateLoadingLayout(Context context, PullToRefreshBase.Mode mode, PullToRefreshBase.Orientation scrollDirection, TypedArray attrs, int layoutId) {
super(context, mode, scrollDirection, attrs, layoutId);
mRotateDrawableWhilePulling=attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);
mHeaderImage.setScaleType(ScaleType.MATRIX);
mHeaderImageMatrix=new Matrix();
mHeaderImage.setImageMatrix(mHeaderImageMatrix);
mRotateAnimation=new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
mRotateAnimation.setRepeatCount(Animation.INFINITE);
mRotateAnimation.setRepeatMode(Animation.RESTART);
}
public void mahang (View view){
AnimationSet set = new AnimationSet(false);
TranslateAnimation tras = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2);
// ������ʾʱ�䳤��
tras.setDuration(2000);
// �����ظ�����
tras.setRepeatCount(2);
// ���ö����ظ���ģʽ
tras.setRepeatMode(Animation.REVERSE);
RotateAnimation rotate = new RotateAnimation(360, 0,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// ������ʾʱ�䳤��
rotate.setDuration(2000);
// �����ظ�����
rotate.setRepeatCount(2);
// ���ö����ظ���ģʽ
rotate.setRepeatMode(Animation.REVERSE);
ScaleAnimation scale = new ScaleAnimation(4f, 0.2f, 4f, 0.2f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// ������ʾʱ�䳤��
scale.setDuration(2000);
// �����ظ�����
scale.setRepeatCount(2);
// ���ö����ظ���ģʽ
scale.setRepeatMode(Animation.REVERSE);
Animation alpha = new AlphaAnimation(1f, 0.1f);
// ������ʾʱ�䳤��
alpha.setDuration(2000);
// �����ظ�����
alpha.setRepeatCount(2);
// ���ö����ظ���ģʽ
alpha.setRepeatMode(Animation.REVERSE);
set.addAnimation(tras);
set.addAnimation(alpha);
set.addAnimation(rotate);
set.addAnimation(scale);
// ��ImageView�ϲ��Ŷ���
iv.startAnimation(set);
}
private void loadProducts() {
if (mFtsHelper.isFtsCredentialsAvailiable(this)) {
final RotateAnimation spinAnim = new RotateAnimation(360, 0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
spinAnim.setInterpolator(new LinearInterpolator());
spinAnim.setDuration(2000);
spinAnim.setRepeatCount(Animation.INFINITE);
mLayoutLoadingProducts.setVisibility(View.VISIBLE);
mImageViewLoadingProducts.setVisibility(View.VISIBLE);
mImageViewLoadingProducts.startAnimation(spinAnim);
mTextViewLoadingProducts.setText(getString(R.string.ttl_loading_products));
updateControlsState();
IDownloadProductsListener downloadProductsListener = new IDownloadProductsListener() {
@Override
public void onDownload(List<ProductEntry> productEntries, String payeeName) {
spinAnim.cancel();
spinAnim.reset();
mLayoutLoadingProducts.setVisibility(View.GONE);
transaction.getProductEntries().clear();
transaction.getProductEntries().addAll(productEntries);
getIntent().removeExtra("load_products");
fillProductList();
if ((viewPager.getCurrentItem() == 0) && mPayeeName != null && mPayeeName.isEmpty()) {
setPayeeName(payeeName);
}
isErrorLoadingProducts = false;
}
@Override
public void onAccepted() {
initProductList();
}
@Override
public void onFailure(String errorMessage, boolean tryAgain) {
isErrorLoadingProducts = true;
getIntent().removeExtra("load_products");
spinAnim.cancel();
spinAnim.reset();
mImageViewLoadingProducts.setVisibility(View.GONE);
mTextViewLoadingProducts.setText(errorMessage);
updateControlsState();
}
};
unsubscribeOnDestroy(mFtsHelper.downloadProductEntryList(transaction, downloadProductsListener));
} else {
mLayoutLoadingProducts.setVisibility(View.GONE);
fillProductList();
if (!mPreferences.getBoolean(FgConst.PREF_FTS_DO_NOT_SHOW_AGAIN, false)) {
startActivityForResult(
new Intent(ActivityEditTransaction.this, ActivityFtsLogin.class),
RequestCodes.REQUEST_CODE_ENTER_FTS_LOGIN);
}
}
}