下面列出了android.graphics.drawable.AnimationDrawable#start() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 自己去调整
*/
private void initAnimation() {
// 获取ImageView上的动画背景
AnimationDrawable spinnerLive = (AnimationDrawable) mIvLive.getBackground();
// 开始动画
spinnerLive.start();
mIvImg = (ImageView) findViewById(R.id.img_img);
// 获取ImageView上的动画背景
AnimationDrawable spinnerImg = (AnimationDrawable) mIvImg.getBackground();
// 开始动画
spinnerImg.start();
}
private void setTypingAnimation(boolean start) {
if (actionBarLayer == null) {
return;
}
if (start) {
try {
actionBarLayer.setSubTitleIcon(R.drawable.typing_dots, OSUtilities.dp(4));
AnimationDrawable mAnim = (AnimationDrawable) actionBarLayer.getSubTitleIcon();
mAnim.setAlpha(200);
mAnim.start();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else {
actionBarLayer.setSubTitleIcon(0, 0);
}
}
public static Dialog createLoadingDialog(Context context, String msg) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(IdHelper.getLayout(context, "jmui_loading_view"), null);
RelativeLayout layout = (RelativeLayout) v.findViewById(IdHelper.getViewID(context, "jmui_dialog_view"));
ImageView mLoadImg = (ImageView) v.findViewById(IdHelper.getViewID(context, "jmui_loading_img"));
TextView mLoadText = (TextView) v.findViewById(IdHelper.getViewID(context, "jmui_loading_txt"));
AnimationDrawable mDrawable = (AnimationDrawable) mLoadImg.getDrawable();
mDrawable.start();
mLoadText.setText(msg);
final Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);
loadingDialog.setCancelable(true);
loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
return loadingDialog;
}
protected ConfigBean buildLoading(ConfigBean bean){
View root = View.inflate(bean.context, R.layout.loading,null);
ImageView gifMovieView = (ImageView) root.findViewById(R.id.iv_loading);
AnimationDrawable drawable = (AnimationDrawable) gifMovieView.getDrawable();
if(drawable!=null){
drawable.start();
}
TextView tvMsg = (TextView) root.findViewById(R.id.loading_msg);
tvMsg.setText(bean.msg);
bean.dialog.setContentView(root);
return bean;
}
@Override
public void headerRefreshing() {
pull_to_refresh_image.setImageDrawable(null);
pull_to_refresh_image.clearAnimation();
pull_to_refresh_image.setVisibility(View.GONE);
pull_to_refresh_image1.setVisibility(View.VISIBLE);
pull_to_refresh_image1.setImageResource(R.drawable.simple_loading);
AnimationDrawable mAnimationDrawable= (AnimationDrawable) pull_to_refresh_image1.getDrawable();
mAnimationDrawable.start();
pull_to_refresh_text.setText("正在刷新…");
}
@Override
public void headerRefreshing() {
headerText.setText("更新中…");
loading.setImageResource(R.drawable.jd_loading);
AnimationDrawable mAnimationDrawable= (AnimationDrawable) loading.getDrawable();
mAnimationDrawable.start();
}
public LoadingImageView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setImageResource(R.drawable.anim_yun);
// 加载动画
AnimationDrawable mAnimationDrawable = (AnimationDrawable) getDrawable();
// 默认进入页面就开启动画
if (!mAnimationDrawable.isRunning()) {
mAnimationDrawable.start();
}
}
private void showAnimation() {
// play voice, and start animation
if (message.direct == EMMessage.Direct.RECEIVE) {
voiceIconView.setImageResource(R.anim.voice_from_icon);
} else {
voiceIconView.setImageResource(R.anim.voice_to_icon);
}
voiceAnimation = (AnimationDrawable) voiceIconView.getDrawable();
voiceAnimation.start();
}
@Override
public void onUIRefreshBegin(PtrFrameLayout frame) {
// 开始刷新
mState = STATE_BEGIN;
// 隐藏商品logo
mGoodsIv.setVisibility(View.GONE);
// 开启跑步动画
mManIv.setBackgroundResource(R.drawable.jd_refresh_header_anim);
mAnimation = (AnimationDrawable) mManIv.getBackground();
if (!mAnimation.isRunning()) {
mAnimation.start();
}
}
public void onWindowFocusChanged(boolean hasFocus){
if (commProgressDialog == null){
return;
}
ImageView imageView = (ImageView) commProgressDialog.findViewById(R.id.iv_loading);
if(anim!=0) {
imageView.setBackgroundResource(anim);
}
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
animationDrawable.start();
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
inflate = LayoutInflater.from(this);
activity_base = inflate.inflate(R.layout.activity_base, null, false);
activity = inflate.inflate(layoutResID, null, false);
// content
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
activity.setLayoutParams(params);
RelativeLayout mContainer = activity_base.findViewById(R.id.container);
mContainer.addView(activity);
getWindow().setContentView(activity_base);
llProgressBar = getView(R.id.ll_progress_bar);
refresh = getView(R.id.ll_error_refresh);
ImageView img = getView(R.id.img_progress);
// 加载动画
mAnimationDrawable = (AnimationDrawable) img.getDrawable();
// 默认进入页面就开启动画
if (!mAnimationDrawable.isRunning()) {
mAnimationDrawable.start();
}
if(mIsSupportToolBar){
setToolBar();
}else{
toolBar = getView(R.id.tool_bar);
toolBar.setVisibility(View.GONE);
}
// 点击加载失败布局
refresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showLoading();
onRefresh();
}
});
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViews = new SparseArray<>();
mLlProgressBar = getView(R.id.ll_progress_bar);
ImageView img = getView(R.id.img_progress);
mRefresh = getView(R.id.ll_error_refresh);
// 加载动画
mAnimationDrawable = (AnimationDrawable) img.getDrawable();
initView();
isInit = true;
isCanLoadData();
Log.d("Meteorite","onActivityCreated mAnimationDrawable.isRunning() = "+mAnimationDrawable.isRunning());
// 默认进入页面就开启动画
if (!mAnimationDrawable.isRunning()) {
mAnimationDrawable.start();
}
// 点击加载失败布局
mRefresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showLoading();
onRefresh();
}
});
//contentView.setVisibility(View.GONE);
}
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.btn_start_upload:
ivUpload.setBackgroundResource(R.drawable.frame_animation_upload);
AnimationDrawable uploadAnimation = (AnimationDrawable) ivUpload.getBackground();
uploadAnimation.start();
break;
case R.id.btn_start_sound:
ivSound.setBackgroundResource(R.drawable.frame_animation_sound);
AnimationDrawable uploadAnimation2 = (AnimationDrawable) ivSound.getBackground();
uploadAnimation2.start();
break;
case R.id.btn_start_loading:
ivLoading.setBackgroundResource(R.drawable.rotation_animation1);
Animatable uploadAnimation1 = (Animatable) ivLoading.getBackground();
uploadAnimation1.start();
break;
case R.id.btn_start_loading2:
Animation a = AnimationUtils.loadAnimation(getContext(),
R.anim.rotation_animation2);
a.setInterpolator(new android.view.animation.Interpolator() {
//总共有多少帧(具体根据图片来设置)
private final int frameCount = 12;
@Override
public float getInterpolation(float input) {
return (float) Math.floor(input * frameCount) / frameCount;
}
});
a.setDuration(1500);
ivLoading2.startAnimation(a);
break;
case R.id.iv_loading3:
ivLoading3.toggleAnimation();
break;
}
}
private void startAnimation() {
if (mMessage.getBelongId().equals(UserManager.getInstance().getCurrentUserObjectId())) {
display.setImageResource(R.drawable.animationlist_chat_voice_left);
} else {
display.setImageResource(R.drawable.animationlist_chat_voice_right);
}
mAnimationDrawable = (AnimationDrawable) display.getDrawable();
mAnimationDrawable.start();
}
private void setupAnimationDrawable() {
AnimationDrawable animationDrawable = new AnimationDrawable();
for (int index = 0; index < bitmaps.size(); index++) {
BitmapDrawable drawable = new BitmapDrawable(this.getResources(), bitmaps.get(index));
animationDrawable.addFrame(drawable, 1000 / framesPerSecond);
}
animationDrawable.setOneShot(!this.loop);
this.setImageDrawable(animationDrawable);
animationDrawable.start();
}
public void onWindowFocusChanged(boolean hasFocus){
ImageView imageView = (ImageView) findViewById(context.getResources().getIdentifier("spinnerImageView", "id", context.getPackageName()));
AnimationDrawable spinner = (AnimationDrawable) imageView.getBackground();
spinner.start();
}
static View setupView(Activity activity, View convertView, ViewGroup parent,
MediaDescription description, int state) {
if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
initializeColorStateLists(activity);
}
MediaItemViewHolder holder;
Integer cachedState = STATE_INVALID;
if (convertView == null) {
convertView = LayoutInflater.from(activity)
.inflate(R.layout.media_list_item, parent, false);
holder = new MediaItemViewHolder();
holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
convertView.setTag(holder);
} else {
holder = (MediaItemViewHolder) convertView.getTag();
cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache);
}
holder.mTitleView.setText(description.getTitle());
holder.mDescriptionView.setText(description.getSubtitle());
// If the state of convertView is different, we need to adapt the view to the
// new state.
if (cachedState == null || cachedState != state) {
switch (state) {
case STATE_PLAYABLE:
holder.mImageView.setImageDrawable(
activity.getDrawable(R.drawable.ic_play_arrow_black_36dp));
holder.mImageView.setImageTintList(sColorStateNotPlaying);
holder.mImageView.setVisibility(View.VISIBLE);
break;
case STATE_PLAYING:
AnimationDrawable animation = (AnimationDrawable)
activity.getDrawable(R.drawable.ic_equalizer_white_36dp);
holder.mImageView.setImageDrawable(animation);
holder.mImageView.setImageTintList(sColorStatePlaying);
holder.mImageView.setVisibility(View.VISIBLE);
animation.start();
break;
case STATE_PAUSED:
holder.mImageView.setImageDrawable(
activity.getDrawable(R.drawable.ic_equalizer1_white_36dp));
holder.mImageView.setImageTintList(sColorStateNotPlaying);
holder.mImageView.setVisibility(View.VISIBLE);
break;
default:
holder.mImageView.setVisibility(View.GONE);
}
convertView.setTag(R.id.tag_mediaitem_state_cache, state);
}
return convertView;
}
public void showLoadingHeader() {
mLoadingIv.setVisibility(View.VISIBLE);
mLoadingTv.setVisibility(View.VISIBLE);
AnimationDrawable drawable = (AnimationDrawable) mLoadingIv.getDrawable();
drawable.start();
}
public void showLoadingHeader() {
mLoadingIv.setVisibility(View.VISIBLE);
mLoadingTv.setVisibility(View.VISIBLE);
AnimationDrawable drawable = (AnimationDrawable) mLoadingIv.getDrawable();
drawable.start();
}
public void showLoadingHeader() {
mLoadingIv.setVisibility(View.VISIBLE);
mLoadingTv.setVisibility(View.VISIBLE);
AnimationDrawable drawable = (AnimationDrawable) mLoadingIv.getDrawable();
drawable.start();
}