Android的插入来自strings.xml档案图片 [英] Android insert an image from strings.xml file

查看:183
本文介绍了Android的插入来自strings.xml档案图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要用我的书里面的一些图片。

Hi guys I need to use some images inside my book.

我的应用程序正在使用碎片和ViewPager用于显示文本,并通过改变其网页上显示相同的TextView新的字符串,所以我不能用ImageView的显示图像在本书的一些地方,我想。

My app is using fragments and ViewPager for displaying texts and by changing page it shows new string on same TextView so I can't use ImageView to show Images in some places of book that I want.

我想通了,它可能是唯一可行的办法就是把它定义里面字符串文件和文本之间,但它并没有被现在的工作。这是我的字符串文件的一部分:

The only way I figured out that it may be possible is to define it inside strings file and between texts, but it doesn't work by now. It's one part of my strings file:

<string name="textch1"><b>CHAPTER ONE</b>
 \n\n<b>The Boy Who Lived</b>
 <img src="file:///android_asset/1.jpg"/>
 \n\nMr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they       were perfectly normal, thank you very much. They were the last people you’d expect to be   involved in anything strange or mysterious, because they just didn’t hold with such   nonsense.
 \n\nMr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere.
</string>

我的形象的名字是1.JPG和它的项目的根内资产的文件夹。

my image name is 1.jpg and it's inside assets folder of project's root.

感谢你们

推荐答案

最简单的方法将是使用的WebView,它允许你格式化对象完全使用HTML和还允许管理文本对齐,怀特,字体,大小等。

The easiest way will be to use a WebView, which allows you to format the object perfectly using html and also allows to manages the text alignment , wight, font, size etc .

尝试使用网页视图,并进行如下操作。

try using a webview and proceed as follows.

WebView view=(WebView) findViewById(R.id.webViev);
        String data=new String();


        data="<html><head></head><body><b>CHAPTER ONE</b> \n\n<b>The Boy Who Lived</b><br/> <img src=\"file:///android_asset/photo.jpg\"  height=\"150\" width=\"150\"/><p>Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they       were perfectly normal, thank you very much. They were the last people you’d expect to be   involved in anything strange or mysterious, because they just didn’t hold with such   nonsense.Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere.</p></body></html>";

        view.loadDataWithBaseURL(null, data,"text/html", "utf-8",null); 

您可以在strings.xml文件中使用的字符串数据。并且要加载的图像被放置在Android,项目的资产文件夹中。无论JPG和PNG格式将图像工作。
您可以使用BASEURL和historyURL。

You can use the string data in your strings.xml file. And the image to be loaded is placed in the assets folder of the android porject. Both jpg and png formats will work for image. You can use the baseUrL and historyURL.

这篇关于Android的插入来自strings.xml档案图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆