最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2018年01月23日 09:43:51   作者:上九樓的快活  
本篇文章主要介紹了Android 帶箭頭的指引tipLayout實(shí)現(xiàn)示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

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

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

引用方式

compile 'com.xiaowei:TriangleTipLayout:1.0.0'

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

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

先上代碼

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);
    }
  }

核心代碼如上,其思路是先繪制一個(gè)矩形,預(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之后會(huì)invalidate()重新繪制;

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

github: 源碼

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

芮城县| 集贤县| 济南市| 吉木乃县| 新邵县| 海口市| 闸北区| 黔东| 弥渡县| 姚安县| 富阳市| 宜良县| 万安县| 德昌县| 镶黄旗| 塔河县| 宁津县| 资阳市| 民丰县| 延边| 崇文区| 育儿| 泾阳县| 三江| 陇西县| 嘉义市| 互助| 库伦旗| 霍州市| 孙吴县| 尉犁县| 营山县| 宣城市| 屏边| 姚安县| 隆安县| 温州市| 无极县| 营山县| 吉安市| 岗巴县|