Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示图像字符串资源(xml)android_Android_Xml_Android Resources - Fatal编程技术网

显示图像字符串资源(xml)android

显示图像字符串资源(xml)android,android,xml,android-resources,Android,Xml,Android Resources,如何在android中以xml格式显示字符串数组中的图像 <string-array name = "cities_info"> <item> <![CDATA[<i><b>Image1:</b> Map of Africa. Cape Town (Afrikaans: Kaapstad [ˈkɑːpstɐt]; Xhosa: Ikapa) is a c

如何在android中以xml格式显示字符串数组中的图像

     <string-array name = "cities_info"> 
    <item>
        <![CDATA[<i><b>Image1:</b> Map of Africa. 
          Cape Town (Afrikaans: Kaapstad [ˈkɑːpstɐt]; Xhosa: Ikapa) is a
          city in South Africa. It ranks third among the most populous urban areas in South Africa, after Johannesburg and Durban, and has roughly the
          same population as the Durban Metropolitan Area. It is also 
          the provincial capital and primate city of the Western Cape
        ]]>
    </item>

图1:非洲地图。
开普敦(南非荷兰语:Kaapstad[kˈkːpstɐt];科萨语:Ikapa)是一个
南非的一座城市。它在南非人口最多的城市地区中排名第三,仅次于约翰内斯堡和德班,人口数量大致相当
与德班都市区人口相同。也是
西开普省首府和灵长类城市
]]>
我试过使用html代码,但不起作用

<img src="capetown.jpg" alt="city" style="width:300px;height:300px;">


您应该在
res/values
文件夹中的
array.xml
文件中为该文件使用

您的xml将如下所示

    <?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="cities_images">
        <item>@drawable/capetown</item>
        <item>@drawable/newyork</item>
        <item>@drawable/losangeles</item>
    </string-array>

</resources>
TypedArray imgs = getResources().obtainTypedArray(R.array.cities_images);

// get resource ID by index
imgs.getResourceId(i, -1)

// or set you ImageView's resource to the id
mImgView1.setImageResource(imgs.getResourceId(i, -1));

// recycle the array
imgs.recycle();

@MukeshRana-是的,这是正确的:-)你不能像这样使用图像。谢谢,但我想把图像(一个小图像)整合到文本本身中。不是一个有图像的数组。好吧,我不认为这是可能的
TypedArray imgs = getResources().obtainTypedArray(R.array.cities_images);

// get resource ID by index
imgs.getResourceId(i, -1)

// or set you ImageView's resource to the id
mImgView1.setImageResource(imgs.getResourceId(i, -1));

// recycle the array
imgs.recycle();