亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Android MarkTipsView文字標識控件使用方法

瀏覽:5日期:2022-09-19 13:17:37

本文實例為大家分享了Android MarkTipsView文字標識控件的具體代碼,供大家參考,具體內容如下

效果預覽

Android MarkTipsView文字標識控件使用方法

使用

使用方式跟TextView使用方式一樣,背景設置直接setBackgroundColor

源碼:

import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.graphics.RectF;import android.util.AttributeSet;import androidx.appcompat.widget.AppCompatTextView;/** * 繪制mark標注 */public class MarkTipsView extends AppCompatTextView { /** * 畫筆 */ private Paint paint; /** * 寬度 */ private int width; /** * 高度 */ private int height; /** * 標識寬度 */ private int markWidth = 12; /** * 標識高度 */ private int markHeight = 12; /** * 圓角大小 */ private float radius = 10; /** * 填充顏色 */ private int solid = Color.parseColor('#F1AA44'); public MarkTipsView(Context context) {super(context);initAttributeSet(context, null); } public MarkTipsView(Context context, AttributeSet attrs) {super(context, attrs);initAttributeSet(context, attrs); } public MarkTipsView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);initAttributeSet(context, attrs); } private void initAttributeSet(Context context, AttributeSet attrs) {paint = new Paint();paint.setDither(true);paint.setAntiAlias(true);paint.setStyle(Paint.Style.FILL);TypedArray array = context.obtainStyledAttributes(attrs,new int[]{android.R.attr.background});solid = array.getInt(0,solid);array.recycle(); } @Override public void setBackgroundColor(int color) {solid = color;invalidate(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);width = getMeasuredWidth();height = getMeasuredHeight(); } @Override protected void onFinishInflate() {super.onFinishInflate();setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom() + markHeight); } @Override protected void onDraw(Canvas canvas) {paint.setColor(solid);//矩形Path path = new Path();RectF rect = new RectF(0, 0, width, height - markHeight);path.addRoundRect(rect, radius, radius, Path.Direction.CCW);//三角形Path onePath = new Path();onePath.lineTo(width / 2 - markWidth, rect.height());onePath.lineTo(width / 2, height);onePath.lineTo(width / 2 + markWidth, rect.height());onePath.close();path.addPath(onePath);//繪制路徑canvas.drawPath(path, paint);super.onDraw(canvas);//重繪文字setText(getText()); } /** * 獲取底部標識箭頭高度 * @return */ public int getMarkHeight() {return markHeight; } /** * 設置底部標識箭頭高度 * @param markHeight */ public void setMarkHeight(int markHeight) {this.markHeight = markHeight;invalidate(); } /** * 獲取底部標識箭頭寬度 * @return */ public int getMarkWidth() {return markWidth; } /** * 設置底部標識箭頭寬度 * @param markWidth */ public void setMarkWidth(int markWidth) {this.markWidth = markWidth;invalidate(); } /** * 獲取圓角大小 * @return */ public float getRadius() {return radius; } /** * 設置圓角大小 * @param radius */ public void setRadius(float radius) {this.radius = radius;invalidate(); }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 婷婷中文 | 免费看欧美一级特黄a毛片 免费看欧美一级特黄α大片 | 成年人在线观看视频网站 | 国产精品一国产精品 | 国产未成女年一区二区 | 亚洲国内自拍 | 男女啪视频大全1000 | 国产极品久久 | 国产高清成人 | 国产男人午夜视频在线观看 | 免费人成又黄又爽的视频在线 | 中国一级特黄aa毛片大片 | 国产精品1024在线观看免费看 | 成人性毛片 | 成人午夜看片 | 精品一区国产 | 成年人网址在线观看 | 视频偷拍一级视频在线观看 | 久久毛片免费看一区二区三区 | 大陆1区二区三区 | 中文偷拍视频在线观看 | 第一区免费在线观看 | 国产在线精品一区二区 | 我我色综合 | 国产小视频在线播放 | 伊人久久国产精品 | 99久久亚洲国产高清观看 | 欧美日韩1区 | 国语自产免费精品视频一区二区 | 久久国产成人 | 国产精品高清一区二区不卡 | 亚洲综合久久久久久888 | 九九视频九九热 | nnnwww在线观看视频 | 毛片网站大全 | 在线免费观看污片 | 欧美精品videossex性护士 | 日韩免费黄色片 | 91高清视频在线观看 | 麻豆精品久久精品色综合 | 国产成人在线网址 |