自定义view


-----------------------vaules/attrs-------------------
<declare-styleable name="ProgressView"
        >
        <!--circleColor 设置圆形边框的颜色  sweepColor设置扇形变换的颜色
         startAngle 设置起始角度 sweepStep 设置变换的步长-->
                 <attr name="circleColor" format="color|reference"></attr>
                 <attr name="sweepColor" format="color|reference"></attr>
                 <attr name="startAngle" format="integer"></attr>
                 <attr name="sweepStep" format="integer"></attr>
                <attr name="padding" format="integer"></attr>
    </declare-styleable>
--------------------------------------------------------------

package com.exbawei.liteli.view;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.util.AttributeSet;import android.view.View;/** * Created by li te li on 2017/10/18. */public class ProgressView extends View { int sweepStep=10; int padding=40; int circleColor= Color.GRAY; int sweepColor=Color.BLUE; int startAngle=90; int storke=10; int sweepAngle=0; int DEFAULT_WIDTH=200; int DEFAULT_HEIGHT = 200; public ProgressView(Context context) { super(context); } public ProgressView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ProgressView); if (array != null) { //获取我们在xml中设置的各个自定义属性 sweepStep = array.getInteger(R.styleable.ProgressView_sweepStep, sweepStep); padding = array.getInteger(R.styleable.ProgressView_padding, padding); circleColor = array.getColor(R.styleable.ProgressView_circleColor, circleColor); sweepColor = array.getColor(R.styleable.ProgressView_sweepColor, sweepColor); startAngle = array.getInteger(R.styleable.ProgressView_startAngle, startAngle); //回收TypeArray资源 array.recycle(); } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(circleColor); mPaint.setStrokeWidth(storke); mPaint.setStyle(Paint.Style.STROKE); canvas.drawCircle(getWidth()/2,getWidth()/2,getWidth()/2-storke/2,mPaint); invalidate();//请求重新绘制view //绘制内部的扇形 mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setColor(sweepColor); RectF rectF = new RectF(padding + storke, padding + storke, getWidth() - padding - storke, getWidth() - padding - storke); canvas.drawArc(rectF, startAngle, sweepAngle, true, mPaint); sweepAngle += sweepStep;//根据步长更新扫过的角度 sweepAngle = sweepAngle > 360 ? 0 : sweepAngle; invalidate();//重绘view } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int wMode = MeasureSpec.getMode(widthMeasureSpec); int hMode = MeasureSpec.getMode(heightMeasureSpec); int wSize = MeasureSpec.getSize(widthMeasureSpec); int hSize = MeasureSpec.getSize(heightMeasureSpec); switch (wMode) { case MeasureSpec.AT_MOST://android:layout_width="warp_content" //获取屏幕像素 float density = getResources().getDisplayMetrics().density; wSize = (int) (DEFAULT_WIDTH * density); hSize = (int) (DEFAULT_HEIGHT * density); break; //当在xml中指定控件的宽高为match_parent或者指定数值的宽高时,回调以下代码 case MeasureSpec.EXACTLY://android:layout_width="match_parent" android:layout_width="40dp" wSize = hSize = Math.min(wSize, hSize); break; } //只要重写onMeasure()方法,一定要调用以下方法,不然会报错 setMeasuredDimension(wSize, hSize); } public ProgressView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }// public ProgressView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {// super(context, attrs, defStyleAttr, defStyleRes);// }}
---------------------------------------------
<com.exbawei.liteli.view.ProgressView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/pv"
    app:circleColor="#aa0000"
   app:sweepColor="#00aa00"
   app:sweepStep="1"
    app:startAngle="180"
    />


 
基于Spring Boot搭建的一个多功能在线学习系统的实现细节。系统分为管理员和用户两个主要模块。管理员负责视频、文件和文章资料的管理以及系统运营维护;用户则可以进行视频播放、资料下载、参与学习论坛并享受个性化学习服务。文中重点探讨了文件下载的安全性和性能优化(如使用Resource对象避免内存溢出),积分排行榜的高效实现(采用Redis Sorted Set结构),敏感词过滤机制(利用DFA算法构建内存过滤树)以及视频播放的浏览器兼容性解决方案(通过FFmpeg调整MOOV原子位置)。此外,还提到了权限管理方面自定义动态加载器的应用,提高了系统的灵活性和易用性。 适合人群:对Spring Boot有一定了解,希望深入理解其实际应用的技术人员,尤其是从事在线教育平台开发的相关从业者。 使用场景及目标:适用于需要快速搭建稳定高效的在线学习平台的企业或团队。目标在于提供一套完整的解决方案,涵盖从资源管理到用户体验优化等多个方面,帮助开发者更好地理解和掌握Spring Boot框架的实际运用技巧。 其他说明:文中不仅提供了具体的代码示例和技术思路,还分享了许多实践经验教训,对于提高项目质量有着重要的指导意义。同时强调了安全性、性能优化等方面的重要性,确保系统能够应对大规模用户的并发访问需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值