国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

ImageGetter顯示Html中的圖片_html/css

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 16:26:43
文檔

ImageGetter顯示Html中的圖片_html/css

ImageGetter顯示Html中的圖片_html/css_WEB-ITnose: ImageGetter 在 TextView 中顯示 html ,需要使用 ImageGetter 解析標(biāo)簽。ImageGetter 是一個(gè)接口,需要實(shí)現(xiàn)里面的方法。 public DrawablegetDrawable(String source); 簡(jiǎn)單的 ImageGetter 實(shí)現(xiàn) 創(chuàng)建一個(gè) Drawab
推薦度:
導(dǎo)讀ImageGetter顯示Html中的圖片_html/css_WEB-ITnose: ImageGetter 在 TextView 中顯示 html ,需要使用 ImageGetter 解析標(biāo)簽。ImageGetter 是一個(gè)接口,需要實(shí)現(xiàn)里面的方法。 public DrawablegetDrawable(String source); 簡(jiǎn)單的 ImageGetter 實(shí)現(xiàn) 創(chuàng)建一個(gè) Drawab

ImageGetter

在 TextView 中顯示 html ,需要使用 ImageGetter 解析標(biāo)簽。ImageGetter 是一個(gè)接口,需要實(shí)現(xiàn)里面的方法。

public DrawablegetDrawable(String source); 

簡(jiǎn)單的 ImageGetter 實(shí)現(xiàn)

創(chuàng)建一個(gè) Drawable 對(duì)象,保留引用并返回,異步請(qǐng)求網(wǎng)絡(luò),獲取圖片,獲取到圖片后,轉(zhuǎn)換為 Bitmap ,交給 Drawable 對(duì)象進(jìn)行繪制。– 自定義 Drawable 對(duì)象

static class MyDrawable extends BitmapDrawable{ BitmapmBitmap; public MyDrawable() { super(); } @Override public void draw(Canvascanvas) { super.draw(canvas); if(mBitmap != null) { canvas.drawBitmap(mBitmap,0,0,getPaint()); } } public void setBitmap(Bitmapbitmap) { mBitmap = bitmap; }} 

  • 實(shí)現(xiàn) getDrawable() 方法

    MyImageGetter 有一個(gè) TextView 成員,用于保存用于圖片顯示的 TextView ,加載完成后,調(diào)用 TextView 的 invalidate() 方法刷新視圖。

  • public MyImageGetter(TextViewview){ mContainer = view;} @Overridepublic DrawablegetDrawable(String s){ // 初始化占位 Drawable final MyDrawabledrawable = new MyDrawable(); // 初始化請(qǐng)求對(duì)象 LocalHostModelmodel = new LocalHostModel(); // 設(shè)置回調(diào)函數(shù) model.setImageListener(new LocalHostModel.OnRequestImageListener() { @Override public void onSuccess(Bitmapbitmap) { // 處理 bitmap 刷新視圖 drawable.setBitmap(bitmap); int height = bitmap.getHeight(); int width = bitmap.getWidth(); drawable.setBounds(0, 0, width, height); mContainer.invalidate(); } @Override public void onFailed(String msg) { Log.i(TAG, "onFailed: " + msg); } }); // 請(qǐng)求圖片 model.requestImage(s); return drawable;} 

    圖片的顯示

  • Drawable.setBounds(Rect) 方法

    The setBounds(Rect) method must be called to tell the Drawable where it is drawn and how large it should be. All Drawables should respect the requested size, often simply by scaling their imagery. A client can find the preferred size for some Drawables with the getIntrinsicHeight() and getIntrinsicWidth() methods.

    Drawable.setBounds(Rect) 用于設(shè)置繪圖的位置,和繪圖的區(qū)域。

  • Canvas.drawBitmap()bitmap 要通過 Drawable.draw(Canvas) 函數(shù)繪制,可以通過 Canvas.drawBitmap() 控制 bitmap 在Drawable 中的顯示位置。

  • 控制圖片居中顯示
  • 首先獲取 TextView 的寬度,減去 paddingLeft paddingRight 即為 Drawable 可用的顯示寬度;
  • 通過上面的兩個(gè)方法配合,控制圖片居中顯示。
  • private void handleBitmap(MyDrawabledrawable, BitmapsrcBitmap){ // 獲取原 bitmap 的大小 int srcHeight = srcBitmap.getHeight(); int srcWidth = srcBitmap.getWidth(); // drawable 可用的顯示寬度 int containerPadding = mContainer.getPaddingLeft() + mContainer.getPaddingRight(); int drawableWidth = mContainer.getMeasuredWidth() - containerPadding; int dstWidth = drawableWidth - mPadding * 2; // 圖片較小,不縮放 if (dstWidth >= srcWidth) { drawable.setBitmap(srcBitmap); // 設(shè)置 drawable 區(qū)域 int drawableHeight = srcHeight + 2 * mPadding; drawable.setBounds(0, 0, drawableWidth, drawableHeight); // 設(shè)置 bitmap 繪制區(qū)域 int left = (drawableWidth - srcWidth) / 2; int top = mPadding; Rectrect = new Rect(left, top, left + srcWidth, top + srcHeight); drawable.setDstRect(rect); } else { // 圖片縮放矩陣 Matrixmatrix = new Matrix(); float scale = (float) dstWidth / srcWidth; matrix.postScale(scale, scale); // 轉(zhuǎn)換 bitmap 為適合 drawable 的大小 BitmapdstBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcWidth, srcHeight, matrix, false); drawable.setBitmap(dstBitmap); // 設(shè)置 drawable 區(qū)域 int dstHeight = srcHeight * drawableWidth / srcWidth; int drawableHeight = dstHeight + 2 * mPadding; drawable.setBounds(0, 0, drawableWidth, drawableHeight); // 設(shè)置 bitmap 繪制區(qū)域 int left = mPadding; int top = mPadding; Rectrect = new Rect(left, top, left + dstWidth, top + dstHeight); drawable.setDstRect(rect); }}static class MyDrawable extends BitmapDrawable{ BitmapmBitmap; RectmSrcRect; RectmDstRect; public MyDrawable(Resourcesres, Bitmapbitmap) { super(res, bitmap); } public void setSrcRect(RectsrcRect) { mSrcRect = srcRect; } public void setDstRect(RectdstRect) { mDstRect = dstRect; } @Override public void draw(Canvascanvas) { super.draw(canvas); // 繪制 bitmap if (mBitmap != null) { if (mSrcRect != null && mDstRect != null) { canvas.drawBitmap(mBitmap, mSrcRect, mDstRect, getPaint()); } else if (mDstRect != null) { int width = mBitmap.getWidth(); int height = mBitmap.getHeight(); RectsrcRect = new Rect(0, 0, width, height); canvas.drawBitmap(mBitmap, srcRect, mDstRect, getPaint()); } else { canvas.drawBitmap(mBitmap, 0, 0, getPaint()); } } } public void setBitmap(Bitmapbitmap) { mBitmap = bitmap; }} 

    參考鏈接

  • Drawable
  • 聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    ImageGetter顯示Html中的圖片_html/css

    ImageGetter顯示Html中的圖片_html/css_WEB-ITnose: ImageGetter 在 TextView 中顯示 html ,需要使用 ImageGetter 解析標(biāo)簽。ImageGetter 是一個(gè)接口,需要實(shí)現(xiàn)里面的方法。 public DrawablegetDrawable(String source); 簡(jiǎn)單的 ImageGetter 實(shí)現(xiàn) 創(chuàng)建一個(gè) Drawab
    推薦度:
    標(biāo)簽: 圖片 顯示 的圖片
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 久久婷婷久久一区二区三区 | 免费看全黄特黄毛片 | 精品久久久久久久久中文字幕 | 日韩电影免费在线观看视频 | 亚洲国产欧美91 | 欧美日韩精品在线观看 | 亚洲视频在线观看 | 日日草视频 | 欧美高清一区二区三区 | 精品视频一区二区三区四区五区 | 殴美激情 | 欧美成人禁片在线www | 国产在线午夜 | 欧美日韩一 | 久久精品国产一区二区 | 亚洲精品在线免费看 | 中文字幕无线码一区 | 国产精品久久久久久一级毛片 | 天堂一区二区三区精品 | 麻豆国产成人精品午夜视频 | 欧美色综合图区 | 中文国产成人精品久久96 | 久久综合社区 | 一本大道香蕉视频在线观看 | 91精品国产99久久 | 日韩欧美精品在线观看 | 啪啪综合网 | 黄动漫3d无遮挡免费观看 | 精品久久一区二区三区 | 精品久久亚洲一级α | 国产片欧美片亚洲片久久综合 | 一区二区三区四区电影 | 成人久久久观看免费毛片 | 在线观看国产亚洲 | 国产精品久久久久久久久久久不卡 | 久久这里只有精品9 | 国产精品久久久久国产精品 | 精品久久久久久久中文字幕 | 久久er99| 亚洲综合欧美在线 | 国产在线a|