欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 运维知识 > android >内容正文

android

android 上下扫描动画,android扫描雷达动画 -凯发k8官方网

发布时间:2024/10/8 android 0 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 android 上下扫描动画,android扫描雷达动画 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

很简单的一个组合动画,用好基本动画啥子效果都不怕

老规矩先上图

效果图.gif

ok 来 既然往下翻那就看看如何实现的吧

首先效果分为两部分

第一部分中间指针(其实这里就是一张图片)

第二部分就是波纹,哈哈 也是图片

给中间图片一个旋转动画,一直转的那种

波纹设置放大和渐变的组合动画,然后中间指针执行一次则波纹动画跟着执行一次

这里我把他自定义为一个scanningview,直接可拿去使用

public class scanningview extends framelayout {

private static final string tag = "scanningview";

/**

* 指针

*/

private imageview ivneedle;

/**

* 波纹

*/

private imageview ivripple;

/**

* 中间文字

*/

private textview tvtitle;

/**

* 装波纹的容器

*/

private framelayout fl_move_circle;

private context context;

public scanningview(context context) {

super(context);

this.context = context;

initview();

}

public scanningview(context context, attributeset attrs) {

super(context, attrs);

initview();

}

private handler handler = new handler() {

@override

public void handlemessage(message msg) {

switch (msg.what) {

case 1:

ivripple.setvisibility(visible);

startoutcircleanim();

break;

case 2:

addmovecircle();

break;

}

}

};

/**

* 设置标题

* @param txt

*/

public void settitle(string txt){

tvtitle.settext(txt);

}

private void initview(){

view v = layoutinflater.from(getcontext()).inflate(r.layout.rotate_view,null);

ivneedle = v.findviewbyid(r.id.iv_btn);

ivripple = v.findviewbyid(r.id.iv_out_circle);

tvtitle = v.findviewbyid(r.id.tv_title);

fl_move_circle = v.findviewbyid(r.id.fl_move_circle);

addview(v, layoutparams.match_parent, layoutparams.match_parent);

startoutcircleanim();

}

/**

* 发散波纹

*/

private void addmovecircle() {

final imageview imageview = new imageview(getcontext());

layoutparams lp = new layoutparams(dip2px(getcontext(), 100), dip2px(getcontext(), 100));

lp.gravity = gravity.center;

imageview.setlayoutparams(lp);

imageview.setimageresource(r.mipmap.outcircle);

fl_move_circle.addview(imageview);

objectanimator outcircleanimx = objectanimator.offloat(imageview, "scalex", 1f, 5f);

objectanimator outcircleanimy = objectanimator.offloat(imageview, "scaley", 1f, 5f);

objectanimator alphaanim = objectanimator.offloat(imageview, "alpha", 0.6f, 0);

outcircleanimx.setduration(5000);

outcircleanimy.setduration(5000);

alphaanim.setduration(5000);

animatorset animatorset = new animatorset();

animatorset.playtogether(outcircleanimx, outcircleanimy, alphaanim);

animatorset.addlistener(new animator.animatorlistener() {

@override

public void onanimationstart(animator animation) {

}

@override

public void onanimationend(animator animation) {

//移除掉刚才添加的波纹

fl_move_circle.removeview(imageview);

}

@override

public void onanimationcancel(animator animation) {

}

@override

public void onanimationrepeat(animator animation) {

}

});

animatorset.start();

}

/**

* 开始循环的放大缩小波纹

*/

private void startoutcircleanim() {

objectanimator outcirclealpha = objectanimator.offloat(ivripple, "alpha", 0.2f, 0.6f);

outcirclealpha.setduration(1000);

objectanimator outcircleanimx = objectanimator.offloat(ivripple, "scalex", 1f, 1.18f, 1f);

objectanimator outcircleanimy = objectanimator.offloat(ivripple, "scaley", 1f, 1.18f, 1f);

outcircleanimx.setduration(2000);

outcircleanimy.setduration(2000);

outcircleanimx.setrepeatcount(valueanimator.infinite);

outcircleanimy.setrepeatcount(valueanimator.infinite);

outcircleanimx.setinterpolator(new linearinterpolator());

outcircleanimy.setinterpolator(new linearinterpolator());

animatorset animatorset = new animatorset();

animatorset.playtogether(outcircleanimx, outcircleanimy, outcirclealpha);

animatorset.start();

}

/**

* 根据手机的分辨率从 dip 的单位 转成为 px(像素)

*/

public static int dip2px(context context, float dpvalue) {

final float scale = context.getresources().getdisplaymetrics().density;

return (int) (dpvalue * scale 0.5f);

}

/**

* 指针转动

*/

private void pressstart() {

animatorset animatorset = new animatorset();

objectanimator scaleyin = objectanimator.offloat(ivneedle, "rotation", 0f, 360f);

scaleyin.setduration(1800);

scaleyin.setinterpolator(new linearinterpolator());

scaleyin.setrepeatcount(valueanimator.infinite);

animatorset.play(scaleyin);

animatorset.start();

}

/**

* 模拟开始

*/

public void onceclick(){

//取消掉循环的波纹

ivripple.setvisibility(gone);

pressstart();

new timer().schedule(new timertask() {

@override

public void run() {

handler.sendemptymessage(2);

}

},0,1800);

}

}

布局文件 rotate_view.xml

android:layout_width="match_parent"

android:background="#69c8fa"

android:layout_height="match_parent">

android:id="@ id/fl_move_circle"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#69c8fa" />

android:id="@ id/iv_out_circle"

android:layout_width="110dp"

android:layout_height="110dp"

android:layout_gravity="center"

android:background="#69c8fa"

android:alpha="0.6"

android:src="@mipmap/outcircle" />

android:id="@ id/iv_btn"

android:layout_width="120dp"

android:layout_height="120dp"

android:layout_gravity="center"

android:src="@mipmap/circle" />

android:id="@ id/tv_title"

android:layout_width="wrap_content"

android:textcolor="#ffffff"

android:layout_gravity="center"

android:text="扫描中"

android:textsize="@dimen/sp_10"

android:layout_margintop="@dimen/dp_13"

android:layout_height="wrap_content" />

直接在布局使用即可

android:id="@ id/scanning"

android:layout_width="match_parent"

android:layout_height="match_parent">

java代码中在调用 onceclick()方法可启动动画

scanningview.onceclick();

如果图片也要的话那就拿去吧

中间的指针

circle.png

波纹

outcircle.png

ok 回手掏,鬼刀一开看不见 ,走位,走位

总结

以上是凯发k8官方网为你收集整理的android 上下扫描动画,android扫描雷达动画的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图