最新国产好看的视频,伊人天堂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)對齊上面的文本,需要?jiǎng)討B(tài)的實(shí)現(xiàn)對其三角形。

引用方式

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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

黑河市| 东乌珠穆沁旗| 阿坝| 巩留县| 元氏县| 黄冈市| 龙胜| 抚远县| 若尔盖县| 玉山县| 射洪县| 顺平县| 定南县| 两当县| 平邑县| 城口县| 大理市| 西青区| 乾安县| 泉州市| 句容市| 五指山市| 鹤岗市| 辽阳市| 福鼎市| 池州市| 巢湖市| 天祝| 库车县| 都江堰市| 石屏县| 自贡市| 砚山县| 南溪县| 广水市| 邹城市| 肥城市| 根河市| 广南县| 杭州市| 巧家县|