您的位置:首页 > 其它

一个常见的一个Dialog动画旋转效果

2017-06-13 15:03 239 查看
在我们进行一个网络访问的过程的时候,我们需要大概1到2秒钟的等待,所以我们给它一个动画效果,当网络访问成功的时候动画随之结束,给用户一个良好的体验效果.写了一个简单的Demo具体代码如下:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button mBt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBt = (Button) findViewById(bt1);
mBt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bt1:
Animal_Custom animal_custom = new Animal_Custom(this,null);
animal_custom.show();
startActivity(new Intent(MainActivity.this,TwoActivity.class));

}
}
}


在跳转第二个页面的时候之前先出现一个动画效果,然后再跳转,以为Intent跳转非常快,所以显示效果不太明显,主要还是用于网络访问的操作等待时间时使用的效果

public class Animal_Custom extends Dialog {
private String data_text;
private Context mContext;
private ImageView mIv_show;
private RelativeLayout mRl_ahow;

public Animal_Custom(Context context, String text) {
super(context);
this.data_text = text;
this.mContext = context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.animal_
4000
layout);
initView();
}

private void initView() {
mIv_show = (ImageView) findViewById(R.id.iv_show);
mRl_ahow = (RelativeLayout) findViewById(R.id.rl_show);
mIv_show.setBackgroundResource(R.drawable.Animal_Scale);
AnimationDrawable background = (AnimationDrawable) mIv_show.getBackground();
background.start();
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.0f,
0.0f, 1.0f, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
scaleAnimation.setDuration(200);
mRl_ahow.startAnimation(scaleAnimation);
Window window = this.getWindow();
WindowManager.LayoutParams params = this.getWindow().getAttributes();
window.setBackgroundDrawable(new BitmapDrawable());
//设置dialog的对话框透明程度背景
params.dimAmount = 0.5f;
window.setAttributes(params);
//点击以外的区域会不消失
setCancelable(false);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK) {
Animal_Custom.this.dismiss();
return false;
}else {
return super.onKeyDown(keyCode, event);
}
}
}


这是 Animal_Scale:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@mipmap/r1"
android:duration="50" />
<item
android:drawable="@mipmap/r2"
android:duration="50" />
<item
android:drawable="@mipmap/r3"
android:duration="50" />
<item
android:drawable="@mipmap/r4"
android:duration="50" />
<item
android:drawable="@mipmap/r5"
android:duration="50" />
<item
android:drawable="@mipmap/r6"
android:duration="50" />
<item
android:drawable="@mipmap/r7"
android:duration="50" />
<item
android:drawable="@mipmap/r8"
android:duration="50" />
<item
android:drawable="@mipmap/r9"
android:duration="50" />
<item
android:drawable="@mipmap/r10"
android:duration="50" />
<item
android:drawable="@mipmap/r11"
android:duration="50" />
<item
android:drawable="@mipmap/r12"
android:duration="50" />
<item
android:drawable="@mipmap/r13"
android:duration="50" />
<item
android:drawable="@mipmap/r14"
android:duration="50" />
<item
android:drawable="@mipmap/r15"
android:duration="50" />
<item
android:drawable="@mipmap/r16"
android:duration="50" />
</animation-list>


这样就会出现一个旋转的图案了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: