【问题标题】:How to add images,links in between string.xml如何添加图像,string.xml 之间的链接
【发布时间】:2018-09-22 15:32:16
【问题描述】:

我在我的项目中添加了滚动活动(textscoll)。所以我想在该活动中添加巨大的文本,并在该巨大文本之间添加几个图像。所以我在 string.xml 中添加了字符串文件并在滚动活动中调用它(content_textscoll .xml)...

我的字符串文件

<string name="string_text_file">This is huge text...</string>

我的 content_textscoll.xml

<TextView
            android:layout_width="wrap_content"
            android:textColor="#000000"
            android:textSize="20dp"
            android:lineSpacingMultiplier="1.3"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:text="@string/string_text_file" />

我的问题是, *我想在上面的文字之间添加几张图片。如何解决这个问题....? 我可以将图像添加到drawble文件夹。如何调用它们? *如何添加html链接或其他活动链接

【问题讨论】:

标签: android xml image scroll textview


【解决方案1】:

制作网页视图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="abhiandroid.com.htmlexample.MainActivity">
<WebView
    android:id="@+id/simpleWebView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp" />
</RelativeLayout>

如果不存在,则制作 assest 文件夹,并在其中使用您想要的任何名称创建新的 html 文件,然后将您的文本和图像放在那里:

<p>in this tag (p tag) put your text </p>
<img>in this tag (img tag) put your images </img>

在你的活动中做这样的事情:

 WebView webView;

public String fileName = "yourAssestFileName.html";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // init webView
    webView = (WebView) findViewById(R.id.simpleWebView);
    // displaying content in WebView from html file that stored in assets folder
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("file:///android_asset/" + fileName);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 2017-06-06
    • 1970-01-01
    相关资源
    最近更新 更多