android的弹窗和几种动画的用法
1.AlertDialog的用法:
1.弹窗:
AlertDialog bulder=new AlertDialog.Builder(this)
.setTitle("标题" )
.setMessage("简单消息框" )
.setPositiveButton("确定" , null )
.show();
//.setIcon(android.R.drawable.ic_dialog_info) 输入一个文本
2.单选框:
ew AlertDialog.Builder(self)
.setTitle("请选择" )
.setIcon(android.R.drawable.ic_dialog_info)
.setSingleChoiceItems(new String[] {"选项1", "选项2", "选项3" , "选项4" }, 0 ,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}
)
.setNegativeButton("取消" , null )
.show();
2.多选宽():
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle("天王盖地虎")
.setMultiChoiceItems(new String[]{"sd","dsds","dsds"},null,null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.show();
3.列表框
new AlertDialog.Builder(self)
.setTitle("列表框" )
.setItems(new String[] {"列表项1", "列表项2", "列表项3" }, null )
.setNegativeButton("确定" , null )
.show();
2.动画:
1. AlphaAnimation(渐变动画)
RelativeLayout rl_splash = (RelativeLayout) findViewById(R.id.rl_splash);
//播放动画效果
AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
//设置Alpha动画的持续时间
animation.setDuration(2000);
//播放Alpha动画
rl_splash.setAnimation(animation);
2. RotateAnimation(旋转动画)
//相对于自身的哪个位置旋转,这里是相对于自身的右下角
RotateAnimation ra = new RotateAnimation(0, 360, //从哪旋转,旋转多少度
Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF,
1.0f);
ra.setDuration(800);
ra.setRepeatCount(Animation.INFINITE);
ra.setRepeatMode(Animation.RESTART);
iv_scan.startAnimation(ra);
3. ScaleAnimation(缩放动画)
ScaleAnimation(float fromX, float toX, float fromY, float toY)
Constructor to use when building a ScaleAnimation from code
4. TranslateAnimation(位移动画)
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)
Constructor to use when building a TranslateAnimation from code
5. AnimationSet (多组动画)
AnimationSet set = new AnimationSet(false);//如果想播放多种动画的组合,这里就要用到了AnimationSet
set.addAnimation(sa);
set.addAnimation(ta);
contentView.startAnimation(set); // 播放一组动画.
9/14/2017 8:02:08 PM