android的弹窗和几种动画的用法_2017.09.14

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值