androidcode
package UICtrl; import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.view.animation.Interpolator;
import android.graphics.Paint;
import android.graphics.PointF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.RelativeLayout; /**
* Created by wangchaomac on 2017/10/18.
*/
public class AroundCircleBall extends RelativeLayout { private BallView mBall; //角度
private float mBallRadius; //小球的颜色
private int mBallColor; private int mCircleRadius; private int mCircleColor; private int mDuration; //笔头描宽
private float mStrokeWidth; private int mInterpolator; private final int ACCELERATE_DECELERATE_INTERPOLATOR = 1; private final int LINEAR_INTERPOLATOR = 2; private final int ACCELERATE = 3; private final int DECELERATE = 4; ObjectAnimator mRotateAnim; PointF mCircleCenterPoint = new PointF(mCircleRadius + mBallRadius, mCircleRadius + mBallRadius);
Paint mPaint = new Paint(); public AroundCircleBall(Context context, AttributeSet attrs){ super(context, attrs);
// TODO Auto-generated constructor stub
init(context); } private void init(Context context){
init();
}
private void init() { mBall = new BallView(getContext());
mBall.setRadius(mBallRadius);
mBall.setBallColor(mBallColor);
//小球的初始位置在圆环的最底部
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.leftMargin = (int) (mCircleRadius);
params.topMargin = (int) (mCircleRadius * 2);
mBall.setLayoutParams(params);
addView(mBall); }
@Override
protected void onDraw(Canvas canvas) {
//绘制圆
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setColor(mCircleColor);
canvas.drawCircle(mCircleCenterPoint.x, mCircleCenterPoint.y, mCircleRadius, mPaint);
super.onDraw(canvas);
} protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//测量控件宽高
int width = (int) (getPaddingLeft() + mCircleRadius * 2 + mBallRadius * 2 + getPaddingRight());
int height = (int) (getPaddingTop() + mCircleRadius * 2 + mBallRadius * 2 + getPaddingBottom());
setMeasuredDimension(width, height);
} private void initRotateAnim(){
mRotateAnim = ObjectAnimator.ofFloat(mBall, "rotation", 0f, 360f);
//计算小球旋转的中心点(此点的左边是在小球自身的坐标系中)
float pivotX = mBall.getRadius();
float pivotY = mBall.getRadius() - mCircleRadius;
mBall.setPivotX(pivotX);
mBall.setPivotY(pivotY);
mRotateAnim.setDuration(mDuration);
mRotateAnim.setInterpolator(getInterpolator());
mRotateAnim.setRepeatCount(-1);
mRotateAnim.setStartDelay(500);
} private Interpolator getInterpolator(){
Interpolator interpolator = null;
switch (mInterpolator){
case ACCELERATE_DECELERATE_INTERPOLATOR: //先加上后减速
interpolator = new AccelerateDecelerateInterpolator();
break;
case LINEAR_INTERPOLATOR: //匀速
interpolator = new LinearInterpolator();
break;
case ACCELERATE: //加速
interpolator = new AccelerateInterpolator();
break;
case DECELERATE: //减速
interpolator = new DecelerateInterpolator();
break;
}
return interpolator;
} /**
* 启动旋转动画
*/ public void startRotate(){
if (mRotateAnim != null){
mRotateAnim.start();
}
} /**
* 暂停旋转动画
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public void pauseRotate(){
if (mRotateAnim != null && mRotateAnim.isRunning()){
mRotateAnim.pause();
}
} /**
* 取消旋转动画
*/
public void cancelRotate(){
if (mRotateAnim != null){
mRotateAnim.cancel();
}
}
}
package UICtrl; import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.view.View; /**
* Created by wangchaomac on 2017/10/18.
*/
public class BallView extends View { private int mBallColor = Color.BLACK;
private float mRadius = 10f;
private PointF mCenterPoint;
private Paint mPaint; public BallView(Context context) {
this(context, null);
} public BallView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
} private void init(){
mPaint = new Paint();
mPaint.setAntiAlias(true);
mCenterPoint = new PointF(mRadius, mRadius);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = (int) (getPaddingLeft() + 2*mRadius + getPaddingRight());
int height = (int) (getPaddingTop() + 2*mRadius + getPaddingBottom());
setMeasuredDimension(width, height);
} @Override
protected void onDraw(Canvas canvas) {
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(mBallColor);
canvas.drawCircle(mCenterPoint.x, mCenterPoint.y, mRadius, mPaint);
} public void setBallColor(int mBallColor) {
this.mBallColor = mBallColor;
} public void setRadius(float radius) {
this.mRadius = radius;
mCenterPoint.set(radius, radius);
} public float getRadius() {
return mRadius;
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources><!--AroundCircleBall自定义属性-->
<declare-styleable name="AroundCircleBall">
<!--绘制圆形轨迹的线宽-->
<attr name="circle_width" format="dimension"></attr>
<!--绘制圆形轨迹的颜色-->
<attr name="circle_color" format="color"></attr>
<!--圆形轨迹的半径-->
<attr name="circle_radius" format="dimension"></attr>
<!--小球的颜色-->
<attr name="ball_color" format="color"></attr>
<!--小球的半径-->
<attr name="ball_radius" format="dimension"></attr>
<!--设置旋转一周需要的时间(单位为秒)-->
<attr name="rotate_duration" format="integer"></attr>
<!--设置旋转动画的补间器-->
<attr name="rotate_interpolator" format="enum">
<enum name="accelerate_decelerate" value="1"/>
<enum name="linear" value="2"/>
<enum name="accelerate" value="3"/>
<enum name="decelerate" value="4"/>
</attr>
</declare-styleable></resources>
androidcode的更多相关文章
- 编译android 4.4.2
1.获取Android源码 (1)下载repo 在用户目录下创建一个bin文件夹来存放repo,并把该路径设置到环境变量中 mkdir ~/bin PATH=~/bin:$PATH 下载repo脚本 ...
- android 通过eclipse混淆代码 打包 + proguard 总结
android应用程序的混淆打包 1 . 在工程文件project.properties中加入下proguard.config=proguard.cfg , 如下所示: target=android- ...
- Android Studio添加应用作为依赖时报错Error:Dependency MonthText:xlistview:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: 及其解决方案
Error:Dependency MonthText:xlistview:unspecified on project app resolves to an APK archive which is ...
- android 混淆配置
proguard 原理Java代码编译成二进制class 文件,这个class 文件也可以反编译成源代码 ,除了注释外,原来的code 基本都可以看到.为了防止重要code 被泄露,我们往往需要混淆( ...
- vue中使用swiper-slide时,循环轮播失效?
前言 vue 项目中使用时,组件swiper-slide 如果用v-for循环的话,loop:true 就不能无缝轮播,每次轮播到最后一张就停止了??? 正文 代码如下: <swiper :op ...
- android 混淆 与 反编译
1, 文件 project.properties 修改: target=android-14proguard.config=${sdk.dir}/tools/proguard/proguard-and ...
- Android中怎样调用拨打电话?
Android系统原本就为手机设计,所以,在android系统中的不论什么App中,仅仅要愿意,拨打指定电话很方便. 核心就是使用Intent跳转,指定请求Action为Intent.ACTION_C ...
- Android开发学习之反编译APK文件
反编译的目的在于学习一些优秀的Android应用程序代码. 在进行反编译之前,需要准备好下面的软件工具(这些文件都放在同一文件下): 这些工具的下载地址:http://down.51cto.com/d ...
- android发送短信样例
Android应用开发中我们经常须要发送手机短信.这对于android平台来说,是最简单只是的功能了,无需太多代码,也无需自己定义代码,仅仅须要调用android提供的消息管理类SmsManager就 ...
随机推荐
- openerp学习笔记 日期时间相关操作
日期格式化字符串:DATE_FORMAT = "%Y-%m-%d" 日期时间格式字符串:DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" ...
- 等待页面元素(webdriverwait)
前言 在脚本中加入太多的 sleep 后会影响脚本的执行速度,虽然 implicitly_wait ()这种方法隐式等待方法一定程度上节省了很多时间.但是一旦页面上某些 js 无法加载出来(其实界面元 ...
- 【随笔】设置title标题图标为自定义图片
第一步: 利用图标工具(有很多)制作图标文件(favicon.ico)上传到网站所在的服务器的根目录下,这个文件必须是16*16大小的图标文件. 第二步: 在<head></head ...
- JNI注册调用完整过程-安卓4.4
在Android系统中,JNI方法是以C/C++语言来实现的,然后编译在一个so文件里面,以我之前的例子为例Android Studio使用JNI,调用之前要加载到当前应用程序的进程的地址空间中: s ...
- python-爬虫之requests模块介绍(登陆github)
介绍 使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) 注意 requests库发送请求将网页内容下载下来以后 ...
- python-入门教程(操作mysql数据库)
pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x,而MySQLdb不支持3.x版本. 本文测试python版本:3.6. ...
- 资料汇总--Java
01.从零开始学springBoot 02.java资源大全中文版 03.谷歌 中国
- 获取URL中某个参数的值
JS代码: function getQueryString(name){ var reg = new RegExp("(^|&)" + name + "=([^& ...
- Rsyslog+ELK日志分析系统搭建总结1.0(测试环境)
因为工作需求,最近在搭建日志分析系统,这里主要搭建的是系统日志分析系统,即rsyslog+elk. 因为目前仍为测试环境,这里说一下搭建的基础架构,后期上生产线再来更新最后的架构图,大佬们如果有什么见 ...
- centos下不重装php——给PHP添加新扩展库
装完php.发现需要一些新扩展库比如常见的mysqli之类的.在不重装php安装新扩展,以一个不常用的库xsl为例. 环境:centos6.8,php5.3.29 ,osx10.11.6 我的php相 ...