当前位置: 首页 > news >正文

网站上传的图片怎么做的清晰东莞市建设

网站上传的图片怎么做的清晰,东莞市建设,windows网页制作工具,东莞龙舟制作技艺实现一个彩虹色进度条功能#xff0c;不说明具体用途大家应该能猜到。想找别人造的轮子#xff0c;但是没有合适的#xff0c;所以决定自己实现一个。 相关知识 android 自定义view LinearGradient 线性渐变 实现步骤 自定义view 自定义一个TmcView类继承View 重写两… 实现一个彩虹色进度条功能不说明具体用途大家应该能猜到。想找别人造的轮子但是没有合适的所以决定自己实现一个。 相关知识 android 自定义view LinearGradient 线性渐变 实现步骤 自定义view 自定义一个TmcView类继承View 重写两个构造方法。构造方法一共有4个这里边重写两个 重写ongSizeChanged方法用来获取控件宽、高来计算内部组件尺寸。 重写onDraw方法里边要描画背景drawBackground分段数据drawSection和seekbar图片drawImage。 import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.View;import androidx.annotation.Nullable;import java.util.List;public class TmcView extends View {public TmcView(Context context) {super(context);}public TmcView(Context context, Nullable AttributeSet attrs) {super(context, attrs);}Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);}Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);drawBackground(canvas);drawSection(canvas);drawImage(canvas);}/*** 画背景* param canvas 画布*/private void drawBackground(Canvas canvas) {}/*** 画分段数据* param canvas 画布*/private void drawSection(Canvas canvas) {}/*** 画图片* param canvas 画布*/private void drawImage(Canvas canvas) {}/*** 更新view* param total 总长度* param rest 剩余长度* param sections 分段数据*/public void updateView(int total, int rest, ListSectionData sections){} 实现几个重构方法 标注 整体宽度为图片宽度44px 背景条宽度30px外边距7px圆角15px 带颜色的条宽度20xp外边距5px圆角15px 自定义view的坐标轴是以view的左上角位置为原点向右为x轴正方向向下为y轴正方向 在视图中用RectF创建背景和颜色条并在onSizeChanged中设置尺寸 public class TmcView extends View {private final RectF backgroundRectF new RectF();private final RectF colorRectF new RectF();public TmcView(Context context) {super(context);}public TmcView(Context context, Nullable AttributeSet attrs) {super(context, attrs);}Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);//设置矩形 left top right bottom 左上右下点的值 按照标注计算得出backgroundRectF.set(7, 0, 37, h);colorRectF.set(12, 5, 32, h-5);}... } 绘制背景条 实现drawBackground方法画背景需要一根画笔Paint 为了避免重复创建声明为成员变量 public class TmcView extends View {/*背景画笔*/private final Paint backPaint new Paint(Paint.ANTI_ALIAS_FLAG);private final RectF backgroundRectF new RectF();private final RectF colorRectF new RectF();public TmcView(Context context) {super(context);}public TmcView(Context context, Nullable AttributeSet attrs) {super(context, attrs);}Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);//设置矩形 left top right bottom 左上右下点的值 按照标注计算得出backgroundRectF.set(7, 0, 37, h);colorRectF.set(12, 5, 32, h-5);}Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);drawBackground(canvas);drawSection(canvas);drawImage(canvas);}/*** 画背景* param canvas 画布*/private void drawBackground(Canvas canvas) {backPaint.setStyle(Paint.Style.FILL);backPaint.setAntiAlias(true); //抗锯齿backPaint.setColor(Color.parseColor(#FFFFFF));//画圆角矩形15为圆角的角度canvas.drawRoundRect(backgroundRectF, 15, 15, backPaint);} ... }布局中加入TmcView com.bigxuan.tesapp.view.TmcViewandroid:idid/tmcandroid:layout_width44pxandroid:layout_height690pxandroid:layout_marginEnd1230pxandroid:layout_marginBottom100pxapp:layout_constraintBottom_toBottomOfparentapp:layout_constraintEnd_toEndOfparent/ 绘制颜色条 实现drawSection方法这里要用到线性渐变LinearGradient LinearGradient 简单说指定每一段的颜色和位置百分比就能实现每一段显示不同颜色。 但它默认是渐变色要想不变就在每一段的开始和结束位置都设置相同的颜色。 再创建一个画笔 Paint画颜色条 public class TmcView extends View {private final Paint backPaint new Paint(Paint.ANTI_ALIAS_FLAG);private final Paint colorPaint new Paint(Paint.ANTI_ALIAS_FLAG);private final RectF backgroundRectF new RectF();private final RectF colorRectF new RectF();public TmcView(Context context) {super(context);}public TmcView(Context context, Nullable AttributeSet attrs) {super(context, attrs);}Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);//设置矩形 left top right bottom 左上右下点的值 按照标注计算得出backgroundRectF.set(7, 0, 37, h);colorRectF.set(12, 5, 32, h-5);}Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);drawBackground(canvas);drawSection(canvas);drawImage(canvas);}/*** 画背景* param canvas 画布*/private void drawBackground(Canvas canvas) {backPaint.setStyle(Paint.Style.FILL);backPaint.setAntiAlias(true); //抗锯齿backPaint.setColor(Color.parseColor(#FFFFFF));//画圆角矩形15为圆角的角度canvas.drawRoundRect(backgroundRectF, 15, 15, backPaint);}/*** 画分段数据* param canvas 画布*/private void drawSection(Canvas canvas) {int[] colorArray {Color.parseColor(#FF0000), Color.parseColor(#FF0000),Color.parseColor(#00FF00), Color.parseColor(#00FF00),Color.parseColor(#0000FF), Color.parseColor(#0000FF)};float[] positionArray {0f, 0.2f,0.2f, 0.6f,0.6f, 1f};colorPaint.setStyle(Paint.Style.FILL);colorPaint.setAntiAlias(true);//指定渐变色方向x轴方向不变沿y方向渐变渐变范围为 颜色条高度colorPaint.setShader(new LinearGradient(0, 0, 0, colorRectF.bottom, colorArray, positionArray, Shader.TileMode.REPEAT));canvas.drawRoundRect(colorRectF,15, 15, colorPaint);}... } 绘制进度图片 app加入图片资源根据资源id获取bitmap对象绘制。 需要注意的是坐标轴的顶点在左上角绘制图片时也是以图片左上顶点位置做定位图片位置是view的高度减掉图片的高度才能显示在正确位置。 public class TmcView extends View {private Context context;private final Paint backPaint new Paint(Paint.ANTI_ALIAS_FLAG);private final Paint colorPaint new Paint(Paint.ANTI_ALIAS_FLAG);private final RectF backgroundRectF new RectF();private final RectF colorRectF new RectF();/*图片资源id*/private int imgResId;/*图片位置*/private int imgPos;public TmcView(Context context) {super(context);}public TmcView(Context context, Nullable AttributeSet attrs) {super(context, attrs);this.context context;this.imgResId R.drawable.icon_seekbar_day;}Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);//设置矩形 left top right bottom 左上右下点的值 按照标注计算得出backgroundRectF.set(7, 0, 37, h);colorRectF.set(12, 5, 32, h-5);imgPos h - 44; // 设置一个初始位置}Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);drawBackground(canvas);drawSection(canvas);drawImage(canvas);}/*** 画背景* param canvas 画布*/private void drawBackground(Canvas canvas) {backPaint.setStyle(Paint.Style.FILL);backPaint.setAntiAlias(true); //抗锯齿backPaint.setColor(Color.parseColor(#FFFFFF));//画圆角矩形15为圆角的角度canvas.drawRoundRect(backgroundRectF, 15, 15, backPaint);}/*** 画分段数据* param canvas 画布*/private void drawSection(Canvas canvas) {int[] colorArray {Color.parseColor(#FF0000), Color.parseColor(#FF0000),Color.parseColor(#00FF00), Color.parseColor(#00FF00),Color.parseColor(#0000FF), Color.parseColor(#0000FF)};float[] positionArray {0f, 0.2f,0.2f, 0.6f,0.6f, 1f};colorPaint.setStyle(Paint.Style.FILL);colorPaint.setAntiAlias(true);//指定渐变色方向x轴方向不变沿y方向渐变渐变范围为 颜色条高度colorPaint.setShader(new LinearGradient(0, 0, 0, colorRectF.bottom, colorArray, positionArray, Shader.TileMode.REPEAT));canvas.drawRoundRect(colorRectF,15, 15, colorPaint);}/*** 画图片* param canvas 画布*/private void drawImage(Canvas canvas) {Bitmap bitmap initBitmap(imgResId);canvas.save();canvas.translate(0, 0);canvas.drawBitmap(bitmap, 0, imgPos, null);canvas.restore();}/*** 通过资源id 创建bitmap* param resId 资源id* return*/private Bitmap initBitmap(int resId) {Bitmap originalBmp BitmapFactory.decodeResource(context.getResources(), resId);return Bitmap.createScaledBitmap(originalBmp, 44, 44, true);} ... } 公共方法 暴露方法用来更新进度updateView 定义一个图片有效的运动距离为view高度减掉图片高度函数参数为总距离和剩余距离计算百分比后乘以有效运动距离得出图片描画位置。最后调用invalidate方法刷新view import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.LinearGradient; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Shader; import android.util.AttributeSet; import android.view.View;import androidx.annotation.Nullable;import com.navinfo.tesapp.R;import java.util.List;public class TmcView extends View {private Context context;private final Paint backPaint new Paint(Paint.ANTI_ALIAS_FLAG);private final Paint colorPaint new Paint(Paint.ANTI_ALIAS_FLAG);private final RectF backgroundRectF new RectF();private final RectF colorRectF new RectF();/*图片资源id*/private int imgResId;/*图片位置*/private int imgPos;/*图片有效的运动距离*/private int imgValidHeight;public TmcView(Context context) {super(context);}public TmcView(Context context, Nullable AttributeSet attrs) {super(context, attrs);this.context context;this.imgResId R.drawable.icon_seekbar_day;}Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);//设置矩形 left top right bottom 左上右下点的值 按照标注计算得出backgroundRectF.set(7, 0, 37, h);colorRectF.set(12, 5, 32, h-5);imgValidHeight h - 44;imgPos h - 44; // 设置一个初始位置}Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);drawBackground(canvas);drawSection(canvas);drawImage(canvas);}/*** 画背景* param canvas 画布*/private void drawBackground(Canvas canvas) {backPaint.setStyle(Paint.Style.FILL);backPaint.setAntiAlias(true); //抗锯齿backPaint.setColor(Color.parseColor(#FFFFFF));//画圆角矩形15为圆角的角度canvas.drawRoundRect(backgroundRectF, 15, 15, backPaint);}/*** 画分段数据* param canvas 画布*/private void drawSection(Canvas canvas) {int[] colorArray {Color.parseColor(#FF0000), Color.parseColor(#FF0000),Color.parseColor(#00FF00), Color.parseColor(#00FF00),Color.parseColor(#0000FF), Color.parseColor(#0000FF)};float[] positionArray {0f, 0.2f,0.2f, 0.6f,0.6f, 1f};colorPaint.setStyle(Paint.Style.FILL);colorPaint.setAntiAlias(true);//指定渐变色方向x轴方向不变沿y方向渐变渐变范围为 颜色条高度colorPaint.setShader(new LinearGradient(0, 0, 0, colorRectF.bottom, colorArray, positionArray, Shader.TileMode.REPEAT));canvas.drawRoundRect(colorRectF,15, 15, colorPaint);}/*** 画图片* param canvas 画布*/private void drawImage(Canvas canvas) {Bitmap bitmap initBitmap(imgResId);canvas.save();canvas.translate(0, 0);canvas.drawBitmap(bitmap, 0, imgPos, null);canvas.restore();}/**** param resId* return*/private Bitmap initBitmap(int resId) {Bitmap originalBmp BitmapFactory.decodeResource(context.getResources(), resId);return Bitmap.createScaledBitmap(originalBmp, 44, 44, true);}/*** 更新view* param total 总长度* param rest 剩余长度* param sections 分段数据*/public void updateView(int total, int rest, ListSectionData sections){float percent (1f * rest) / total;//防止溢出if(percent 0){return;}imgPos (int)(percent * imgValidHeight);invalidate();} } updateView方法还有第三个参数是用来传出颜色条不同段的颜色和百分比数据的。根据此数据来更新颜色条。这里需要根据业务不同自己实现我这里就不写了。 总结 大家可能看出来了这个视图是用来展示导航中不同路段交通情况和当前车辆进度用的。自定义view中可以在构造方法中获取一些自定义属性像背景条和颜色条的边距、圆角这些都可以定义到xml中因为只适配一种屏幕尺寸所以也没有做多尺寸适配。以前也没有做过这次记录下来。
http://www.hkea.cn/news/14285658/

相关文章:

  • 网站建设与管理岗位国内做网站公司排名
  • 安徽省建设厅网站官网信息发布网站开发模板
  • 正在建设中的网站可算违规表白网页制作免费网站
  • 红色大气网站互联网网站制作公司哪家好
  • 宣讲家网站两学一做心得wordpress下雪
  • 统计局网站建设情况免费咨询男性问题
  • 给女朋友做网站的素材百度信息流
  • 作作网站北京兼职做网站建设
  • 企业网站建设专业服务wordpress 颜色插件下载
  • 自己做网站好还是让别人做1688品牌加盟网
  • 在哪个网站做流动补胎的广告好短网址压缩
  • 微信公众号里怎么做网站网络营销郑州网站搭建方案
  • 二级菜单网站如何做伪静态怎样查公司注册信息查询
  • 河南seo网站开发小程序开发哪家好
  • 餐饮加盟网站模板视频素材网站大全免费
  • 汉中微信网站建设公司做城市网站的标语
  • 湖北长安建设集团股份有限公司网站权重查询
  • 建设食品网站的目的临猗网站建设
  • 上海南京东路网站建设东莞百度提升优化
  • 网站推广目标关键词查项目经理有没有在建怎么查
  • 整站优化提升排名杭州百度推广代理公司哪家好
  • 做网站维护需要多少钱网站推广常用方法
  • 做教师知识网站有哪些内容怎么把网站排名优化
  • 综合门户网站是什么意思html5网页模板代码
  • 温岭市建设工程质量安全网站保定外贸网站制作
  • 微信网站建设价格推广渠道的优缺点
  • 工程建设造价信息网站我要设计网
  • 网站制作系统网站建设为什么要推广
  • 搜索关键词站长工具wordpress如何添加背景音乐
  • 网站备案用的幕布可以淘宝做吗永久云虚拟主机