Android簡(jiǎn)單實(shí)現(xiàn)圓盤抽獎(jiǎng)界面
閑來無(wú)事,做了一個(gè)簡(jiǎn)單的抽獎(jiǎng)轉(zhuǎn)盤的ui實(shí)現(xiàn),供大家參考

package com.microchange.lucky;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
public class HalfCircle extends View {
private Paint paint;
private RectF oval;
private float startAngle;
private float sweepSpeed;
private float sweepAngle;
boolean useCenter;
int count;// 等份
@Override
protected void onDraw(Canvas canvas) {
setSweepAngle(count);
while (startAngle <= 360) {
if (startAngle % (count*3) == 0) {
paint.setColor(Color.BLUE);
} else if (startAngle % (count*2) == 0){
paint.setColor(Color.GREEN);
}else {
paint.setColor(Color.RED);
}
Log.e(""+startAngle, paint.getColor()+"");
canvas.drawArc(oval, startAngle, sweepAngle, useCenter, paint);
startAngle += count;
}
float centerX = oval.centerX();
float centerY = oval.centerY();
paint.setColor(Color.WHITE);
// paint.setStrokeWidth(5);
// paint.setStyle(Paint.Style.STROKE); //設(shè)置空心
paint.setAntiAlias(true); //消除鋸齒
canvas.drawCircle(centerX, centerY, 50, paint);
String text = "獎(jiǎng)";
paint.setTextSize(20 * getContext().getResources().getDisplayMetrics().density);
float measureText = paint.measureText(text);
float textY = paint.descent() - paint.ascent();
paint.setColor(Color.RED);
// canvas.drawLine(0, centerY, 480, centerY, paint);
// canvas.drawText(text, centerX-(measureText/2), centerY, paint);
canvas.drawText(text, centerX-(measureText/2), centerY+(textY/4), paint);
}
private void init() {
paint = new Paint();
paint.setColor(Color.BLUE);
paint.setAntiAlias(true);
paint.setStrokeWidth(5);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
/**
* @return the count
*/
public int getCount() {
return count;
}
/**
* @param count the count to set
*/
public void setCount(int count) {
this.count = 360 / count;
}
public Paint getPaint() {
return paint;
}
public void setPaint(Paint paint) {
this.paint = paint;
}
public RectF getOval() {
return oval;
}
public void setOval(RectF oval) {
this.oval = oval;
}
public float getStartAngle() {
return startAngle;
}
public void setStartAngle(float startAngle) {
this.startAngle = startAngle;
}
public float getSweepSpeed() {
return sweepSpeed;
}
public void setSweepSpeed(float sweepSpeed) {
this.sweepSpeed = sweepSpeed;
}
public float getSweepAngle() {
return sweepAngle;
}
public void setSweepAngle(float sweepAngle) {
this.sweepAngle = sweepAngle;
}
public boolean isUseCenter() {
return useCenter;
}
public void setUseCenter(boolean useCenter) {
this.useCenter = useCenter;
}
public HalfCircle(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public HalfCircle(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public HalfCircle(Context context) {
this(context, null, 0);
}
}
package com.microchange.lucky;
import android.app.Activity;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.RotateAnimation;
public class MainActivity extends Activity {
RectF rect;
int radius = 300;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HalfCircle circle = new HalfCircle(getApplicationContext());
circle.setOval(getRectF());
// circle.setStartAngle(90);
circle.setUseCenter(true);
circle.setCount(9);
Animation animation = new RotateAnimation(0, 135*10, getRectF().centerX(), getRectF().centerY());
animation.setDuration(5000);
animation.setInterpolator(new DecelerateInterpolator());
// animation.setRepeatCount(-1);
circle.setAnimation(animation );
// animation.start();
setContentView(circle);
}
public RectF getRectF(){
if (rect==null){
// getWindow().getDecorView().getWidth()
int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
int top = (height - radius)/2;
int left = (width - radius)/2;
rect = new RectF(left, top, left+radius, top+radius);
}
return rect;
}
}
希望本文所述對(duì)大家學(xué)習(xí)Android程序設(shè)計(jì)有所幫助。
- Android 實(shí)現(xiàn)九宮格抽獎(jiǎng)功能
- Android自定義view制作抽獎(jiǎng)轉(zhuǎn)盤
- Android自定義View實(shí)現(xiàn)抽獎(jiǎng)轉(zhuǎn)盤
- Android自定義View實(shí)現(xiàn)QQ運(yùn)動(dòng)積分轉(zhuǎn)盤抽獎(jiǎng)功能
- Android抽獎(jiǎng)輪盤的制作方法
- Android使用surfaceView自定義抽獎(jiǎng)大轉(zhuǎn)盤
- Android打造流暢九宮格抽獎(jiǎng)活動(dòng)效果
- Android中利用SurfaceView制作抽獎(jiǎng)轉(zhuǎn)盤的全流程攻略
- Android App中實(shí)現(xiàn)簡(jiǎn)單的刮刮卡抽獎(jiǎng)效果的實(shí)例詳解
- Android實(shí)現(xiàn)九宮格抽獎(jiǎng)
相關(guān)文章
android TextView中識(shí)別多個(gè)url并分別點(diǎn)擊跳轉(zhuǎn)方法詳解
在本篇文章里小編給大家整理的是關(guān)于android TextView中識(shí)別多個(gè)url并分別點(diǎn)擊跳轉(zhuǎn)方法詳解,需要的朋友們可以學(xué)習(xí)參考下。2019-08-08
Android手勢(shì)ImageView三部曲 第三部
這篇文章主要為大家詳細(xì)介紹了Android手勢(shì)ImageView三部曲的第三部,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03
Android實(shí)現(xiàn)隱藏手機(jī)底部虛擬按鍵
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)隱藏手機(jī)底部虛擬按鍵,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
Android那兩個(gè)你碰不到但是很重要的類之ActivityThread
上篇文章我們聊了些Android里那些我們平時(shí)碰不到但很重要的類ViewRootImpl,這一篇我們就來看看另外那個(gè)類ActivityThread,文中有相關(guān)的代碼示例,感興趣的同學(xué)可以跟著小編一起來學(xué)習(xí)2023-05-05
Android項(xiàng)目仿UC瀏覽器和360手機(jī)衛(wèi)士消息常駐欄(通知欄)
本篇文章主要介紹了Android項(xiàng)目仿UC瀏覽器和360手機(jī)衛(wèi)士消息常駐欄(通知欄),可以仿照360的通知欄,有興趣的可以了解一下。2016-11-11
Spinner在Dialog中的使用效果實(shí)例代碼詳解
這篇文章主要介紹了Spinner在Dialog中的使用效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05
基于popupWindow實(shí)現(xiàn)懸浮半透明效果
這篇文章主要為大家詳細(xì)介紹了基于popupWindow實(shí)現(xiàn)懸浮半透明效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
深入理解TextView實(shí)現(xiàn)Rich Text--在同一個(gè)TextView設(shè)置不同字體風(fēng)格
本篇文章是對(duì)Android中在同一個(gè)TextView中設(shè)置不同的字體風(fēng)格進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
app 請(qǐng)求服務(wù)器json數(shù)據(jù)實(shí)例代碼
下面小編就為大家分享一篇app 請(qǐng)求服務(wù)器json數(shù)據(jù)實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01

