仿微信雷達尋好友動畫,雷達好友動畫

來源:互聯網
上載者:User

仿雷達尋好友動畫,雷達好友動畫

先看看要實現的效果:


這種效果正是類似上雷達尋找好友的動畫,於是解壓看看裡面,發現是用一張圖片做的旋轉動畫,於是乎看看這種特效,可以用畫筆直接畫出來,首先是四個圓,然後中間那部分掃描區便是顏色由透明漸層到淡白。比較簡單。

public class RaderView extends View {    private Paint mPaintCircleLine;//繪製圓邊    private Paint mPaintCircle;    private int width;    private int height;    private Matrix matrix;    private int start;    private Handler handler = new Handler();    private Runnable run = new Runnable() {        @Override        public void run() {            start += 1;            matrix = new Matrix();            matrix.postRotate(start, width / 2, height / 2);            RaderView.this.invalidate();//重新整理重繪            handler.postDelayed(run,30);        }    };    public RaderView(Context context) {        this(context, null);    }    public RaderView(Context context, AttributeSet attrs) {        this(context, attrs, 0);    }    public RaderView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);        initPaint();        //得到當前螢幕的像素寬高        width = context.getResources().getDisplayMetrics().widthPixels;        height = context.getResources().getDisplayMetrics().heightPixels;        matrix = new Matrix();        handler.post(run);    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        setMeasuredDimension(width, height);//設定該控制項的寬高為當前螢幕的寬高    }    private void initPaint() {        mPaintCircleLine = new Paint();        mPaintCircleLine.setColor(Color.parseColor("#a2a2a2"));        mPaintCircleLine.setAntiAlias(true);//消除鋸齒        mPaintCircleLine.setStyle(Paint.Style.STROKE);//設定實心        mPaintCircleLine.setStrokeWidth(2);//畫筆寬度        mPaintCircle = new Paint();        mPaintCircle.setColor(Color.parseColor("#99a2a2a2"));        mPaintCircle.setAntiAlias(true);    }    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        //分別繪製四個圓        canvas.drawCircle(width / 2, height / 2, height / 7, mPaintCircleLine);        canvas.drawCircle(width / 2, height / 2, height / 4, mPaintCircleLine);        canvas.drawCircle(width / 2, height / 2, height / 3, mPaintCircleLine);        canvas.drawCircle(width / 2, height / 2, 3 * height / 7, mPaintCircleLine);        //設定色彩坡形從透明到不透明        Shader shader = new SweepGradient(width / 2, height / 2, Color.TRANSPARENT, Color.parseColor("#50aaaaaa"));        mPaintCircle.setShader(shader);        canvas.concat(matrix);        canvas.drawCircle(width / 2, height / 2, 3 * height / 7, mPaintCircle);    }}
布局檔案:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@mipmap/bg"    tools:context=".MainActivity">    <com.example.raderanim.RaderView        android:layout_width="match_parent"        android:layout_height="match_parent" /></FrameLayout>

這就是整個的動畫效果,可以直接拿來用,加張背景就完全ok了。



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。轉載註明出處:http://blog.csdn.net/u010687392

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.