久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

android - 用textview顯示html時(shí)如何寫imagegetter獲取網(wǎng)絡(luò)圖片

瀏覽:101日期:2024-03-01 10:43:38

問題描述

項(xiàng)目需要實(shí)現(xiàn)圖文混排,后臺(tái)給出來的文本是html格式的,ui要求需要調(diào)整行間距,webview可以顯示各種標(biāo)簽,但是無法調(diào)整行間距,試著往span中添加line-height也失敗了,而且webview無法調(diào)整內(nèi)邊距,且webview中的內(nèi)容可以滑動(dòng),因此不太符合我們的要求最后決定還是使用textview來實(shí)現(xiàn),這樣可以調(diào)整各種樣式,但是在寫imagegetter的時(shí)候遇到一些問題搜索了很久,都只是搜索到一些顯示本地圖片沒有顯示網(wǎng)絡(luò)圖片,網(wǎng)絡(luò)圖片的大致方向也是要保存到本地之后再顯示但是在保存的時(shí)候會(huì)有一些問題,我保存時(shí)不知道為什么有ioexception關(guān)于imagegetter不知道有沒有什么其他的思路

private Html.ImageGetter imageGetter = new Html.ImageGetter() { @Override public Drawable getDrawable(String source) {String url = getApplicationContext().getExternalCacheDir().getPath() + '/image';File dir = new File(url);if (dir.exists()) { Drawable drawable = Drawable.createFromPath(url+source); if (drawable != null){return drawable; }}loadPic(source);return null; }};private void loadPic(final String source){ x.image().loadDrawable(source, ImageOptions.DEFAULT,new Callback.CommonCallback<Drawable>(){@Overridepublic void onSuccess(Drawable result) { super.onSuccess(result); saveImage(source,result,getApplicationContext()); textview.setText(Html.fromHtml(content,imageGetter,null));} });}private void saveImage(String name,Drawable result, Context context) { Bitmap bit = ((BitmapDrawable) result).getBitmap(); String url = context.getExternalCacheDir().getPath() + '/image'; File dir = new File(url); if (!dir.exists()) {dir.mkdirs(); } File file = new File(dir.getAbsolutePath(),name); if (file.exists()) {return url+name; } try {//這里會(huì)出現(xiàn)ioexceptionFileOutputStream fos = new FileOutputStream(file);bit.compress(Bitmap.CompressFormat.JPEG, 100, fos);fos.flush();fos.close();return url+name; } catch (IOException e) {e.printStackTrace();return null; }}

這是我的代碼,不知道又沒有什么其他的好方法解決

問題解答

回答1:

http://git.oschina.net/zzhouj...

在這里找到一個(gè),稍微修改一下可以使用,需要配置picasso,之后如果想到其他可以修改的方法會(huì)貼上來

回答2:

https://github.com/Sufficient...有這樣一個(gè)工具,但并不完美。圖片可以自動(dòng)從網(wǎng)絡(luò)加載,但是沒有本地緩存,而且加載的過程也是異步的,所以你布局的高度會(huì)變得不確定,如果是在listview中的話不推薦使用。

回答3:

之前用過這個(gè),還不錯(cuò),也有默認(rèn)的imagegetter方案,可以參考下。https://github.com/Sufficient...

回答4:

這還有一個(gè)https://github.com/angebagui/...

標(biāo)簽: HTML
相關(guān)文章:
主站蜘蛛池模板: 吉隆县| 闵行区| 阿鲁科尔沁旗| 汝阳县| 申扎县| 和静县| 昌都县| 铜梁县| 黄冈市| 文昌市| 伊春市| 宿松县| 苏尼特右旗| 江都市| 南木林县| 鹿邑县| 黄陵县| 明光市| 靖西县| 溧水县| 蓬莱市| 绿春县| 容城县| 叙永县| 垣曲县| 枝江市| 满城县| 治多县| 额济纳旗| 文成县| 垦利县| 横峰县| 资阳市| 榕江县| 博兴县| 武义县| 五家渠市| 水城县| 龙泉市| 米脂县| 隆回县|