java摇一摇功能_Android学习笔记:摇一摇功能的实现

1 privateShakeManager shake;2

3 shake.setShakeListener(newShakeManager.ShakeListener() {4 @Override5 public voidonShake() {6 QiStart();7 shake.stop();8 canrads.setVisibility(View.GONE);9 soundPool.play(map.get(1),0.3f,0.3f,1,0,0);10 }11 });12

13

14

15 /**

16 * 开始动画17 */

18 private voidQiStart() {19 TranslateAnimation up = newTranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f20 ,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,-0.3f);21 up.setDuration(600L);22 up.setRepeatCount(1);23 up.setRepeatMode(Animation.REVERSE);24 imageshang.startAnimation(up);25

26 TranslateAnimation down = newTranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f27 ,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0.3f);28 down.setDuration(600L);29 down.setRepeatCount(1);30 down.setRepeatMode(Animation.REVERSE);31 imagexia.startAnimation(down);32

33 down.setAnimationListener(newAnimation.AnimationListener() {34 @Override35 public voidonAnimationStart(Animation animation) {36

37 }38 @Override39 public voidonAnimationEnd(Animation animation) {40 xian2.setVisibility(View.VISIBLE);41 newRequestClient(getContext(),requestConfig){42

43 @Override44 protected voidloadSuccess(String result) {45 try{46 result = new String(result.getBytes("ISO-8859-1"),"UTF-8");47 } catch(UnsupportedEncodingException e) {48 e.printStackTrace();49 }50 shakeb = JSONParseUtil.parseObject(result,Shakeb.class);51 assert shakeb != null;52 String title = shakeb.getOwner()!=null ? shakeb.getOwner().getName():"";53 tv_neirong.setText(title);54 tv_biaoti.setText(shakeb.getDescription());55 tv_chakan.setText(String.valueOf(shakeb.getForks_count()));56 tv_xingxing.setText(String.valueOf(shakeb.getStars_count()));57 tv_disange.setText(String.valueOf(shakeb.getWatches_count()));58 //获取图片地址

59 String imageUrl =shakeb.getOwner().getNew_portrait();60 ImageLoader imageLoader =ImageLoaderFactory.getImageLoader();61 //加载图片

62 imageLoader.loadImage(imageUrl,roundImageView);63 //隐藏正在加载

64 xian2.setVisibility(View.GONE);65 //播放声音

66 soundPool.play(map.get(0),0.3f,0.3f,1,0,0);67 //显示推举项目

68 canrads.setVisibility(View.VISIBLE);69 //摇一摇监听开始

70 shake.start();71 }72

73 @Override74 protected voidloadFail() {75

76 }77 }.get(RequestAPI.SHAKE);78 }79

80 @Override81 public voidonAnimationRepeat(Animation animation) {82

83 }84 });85

86 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值