国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android 帶箭頭的指引tipLayout實(shí)現(xiàn)示例代碼

2019-10-22 18:16:33
字體:
供稿:網(wǎng)友

本文介紹了Android 帶箭頭的指引tipLayout實(shí)現(xiàn)示例代碼,分享給大家,具體如下:

Android,指引箭頭,tipLayout

如上是從UI接過來的設(shè)計(jì)圖,要求三角形指示器需要動態(tài)對齊上面的文本,需要動態(tài)的實(shí)現(xiàn)對其三角形。

引用方式

compile 'com.xiaowei:TriangleTipLayout:1.0.0'

實(shí)現(xiàn)思路

準(zhǔn)備一個三角形指引的圖片即可。

先上代碼

final TextPaint textPaint = mTextView.getPaint();    final int textHeight = (int) (textPaint.descent() - textPaint.ascent());    mRect.set(0, DEFAULT_TOP_HEIGHT, getWidth(), getHeight() + textHeight - DEFAULT_TOP_HEIGHT);    canvas.drawRect(mRect, mRectPaint);    final String text = mTextView.getText().toString();    float left = 0;    if (mIsShowTriangle) {      if (mGravity == Gravity.LEFT || mGravity == Gravity.START) {        LayoutParams layoutParams = (LayoutParams) mTarget.getLayoutParams();        left = mTarget.getLeft() - layoutParams.rightMargin - layoutParams.leftMargin;      } else {        if (mTarget instanceof TextView) {          ViewParent viewParent = mTarget.getParent();          float textWidth = textPaint.measureText(text);          if (viewParent instanceof LinearLayout) {            final float width = mTarget.getWidth() / 2;            left = mTarget.getLeft() + width - (mBitmap.getWidth() / 2);          } else if (viewParent instanceof RelativeLayout) {            left = mTarget.getLeft() + textWidth / 2;          }        } else if (mTarget instanceof ImageView) {          final float width = mTarget.getWidth();          left = mTarget.getLeft() + (width / 2) - (mBitmap.getWidth() / 2);        }      }      canvas.drawBitmap(mBitmap, left, 0, mBitmapPaint);    }  }

核心代碼如上,其思路是先繪制一個矩形,預(yù)留出三角形所需要的高度,最后將其三行圖片繪制出來。

配置指示器

mTipsLayout.setRectBackgroundColor(Color.parseColor("#FFF8BE"));    mTipsLayout.setTextColor(Color.parseColor("#FF9B33"));    mTipsLayout.setTriangleBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_triangle_arrow));    mTipsLayout.setTriangleGravity(Gravity.START);    mTipsLayout.bindView(findViewById(R.id.text2));    mTipsLayout.setText("您今日收入已到達(dá)10W+,牛逼。保持努力");

注意:當(dāng)調(diào)用setText之后會invalidate()重新繪制;

實(shí)現(xiàn)效果如下

Android,指引箭頭,tipLayout

github: 源碼

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 民权县| 泸定县| 中西区| 静宁县| 海盐县| 蓬溪县| 中牟县| 庆城县| 资中县| 郯城县| 金湖县| 甘南县| 根河市| 大同县| 张家港市| 威信县| 扶绥县| 汝南县| 罗源县| 武安市| 贺州市| 杭锦后旗| 武汉市| 潼关县| 北川| 霸州市| 黄山市| 桓台县| 余江县| 泗水县| 邵武市| 藁城市| 称多县| 东乌| 乃东县| 社旗县| 会同县| 共和县| 花莲市| 略阳县| 团风县|