Android MarkTipsView文字標(biāo)識控件使用方法
本文實例為大家分享了Android MarkTipsView文字標(biāo)識控件的具體代碼,供大家參考,具體內(nèi)容如下
效果預(yù)覽

使用
使用方式跟TextView使用方式一樣,背景設(shè)置直接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標(biāo)注
*/
public class MarkTipsView extends AppCompatTextView {
/**
* 畫筆
*/
private Paint paint;
/**
* 寬度
*/
private int width;
/**
* 高度
*/
private int height;
/**
* 標(biāo)識寬度
*/
private int markWidth = 12;
/**
* 標(biāo)識高度
*/
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());
}
/**
* 獲取底部標(biāo)識箭頭高度
* @return
*/
public int getMarkHeight() {
return markHeight;
}
/**
* 設(shè)置底部標(biāo)識箭頭高度
* @param markHeight
*/
public void setMarkHeight(int markHeight) {
this.markHeight = markHeight;
invalidate();
}
/**
* 獲取底部標(biāo)識箭頭寬度
* @return
*/
public int getMarkWidth() {
return markWidth;
}
/**
* 設(shè)置底部標(biāo)識箭頭寬度
* @param markWidth
*/
public void setMarkWidth(int markWidth) {
this.markWidth = markWidth;
invalidate();
}
/**
* 獲取圓角大小
* @return
*/
public float getRadius() {
return radius;
}
/**
* 設(shè)置圓角大小
* @param radius
*/
public void setRadius(float radius) {
this.radius = radius;
invalidate();
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android編程實現(xiàn)WebView自適應(yīng)全屏方法小結(jié)
這篇文章主要介紹了Android編程實現(xiàn)WebView自適應(yīng)全屏方法,結(jié)合實例形式總結(jié)了三種常用的WebView自適應(yīng)全屏實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-12-12
Android的HTTP類庫Volley入門學(xué)習(xí)教程
這篇文章主要介紹了Android應(yīng)用開發(fā)框架Volley的入門學(xué)習(xí)教程,Volley適合于輕量級的通信功能開發(fā),善于處理JSON對象,需要的朋友可以參考下2016-02-02
Flutter自定義實現(xiàn)神奇動效的卡片切換視圖的示例代碼
這篇文章主要介紹了Flutter自定義實現(xiàn)神奇動效的卡片切換視圖的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04
Flutter質(zhì)感設(shè)計之模態(tài)底部面板
這篇文章主要為大家詳細介紹了Flutter質(zhì)感設(shè)計之模態(tài)底部面板,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08
android:layout_gravity和android:gravity的區(qū)別
本篇文章主要介紹了android中g(shù)iavity和layout_gravity的區(qū)別。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04
Android dataBinding與ListView及事件詳解
這篇文章主要介紹了Android dataBinding與ListView及事件詳解的相關(guān)資料,需要的朋友可以參考下2016-10-10
android之視頻播放系統(tǒng)VideoView和自定義VideoView控件的應(yīng)用
這篇文章主要介紹了android之視頻播放系統(tǒng)VideoView和自定義VideoView控件的應(yīng)用,需要的朋友可以參考下2017-03-03
Android的Activity跳轉(zhuǎn)動畫各種效果整理
Android的Activity跳轉(zhuǎn)就是很生硬的切換界面。其實Android的Activity跳轉(zhuǎn)可以設(shè)置各種動畫,本文整理了一些,還有很多動畫效果,就要靠我們發(fā)揮自己的想象力2013-06-06
Android實現(xiàn)手電筒電源鍵關(guān)閉功能
這篇文章主要介紹了Android實現(xiàn)手電筒電源鍵關(guān)閉功能,在打開手電筒之后,機器休眠,客戶要求點擊電源鍵,手電筒需要關(guān)閉,下面小編給大家分享實現(xiàn)代碼,需要的朋友可以參考下2017-11-11

