2

我必须在片段中插入一个列表(不是 android 列表视图,而是简单的 html 列表)。布局文件“about.xml”页面只有一个文本视图,它是动态集群的,从 string.xml 文件中获取数据。string.xml 中的声明如下:

<string name="AboutThisApp"><![CDATA[

<div>
    <p>here is the list of functions: </p>
</div>

<ul>
    <li> Sportsmanship</li>
    <li> Participation</li>
    <li> Safety/Risk Minimization</li>
    <li> Sound Traditions of the Sport</li>
    <li> Support for USA Footvall\'s Mission</li>
    <li> Balance Between Offense and Defence</li>
</ul>

]]></string>

此数据正在布局文件夹中的文本视图中访问,如下所示(文件为“about.xml”):

<TextView
            android:id="@+id/textViewAbout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="16dp"
            android:textColor="@color/white"
            android:textSize="16dp"
            customText:textcustomFont="fonts/montserrat-r.ttf" />

访问java文件中数据的对象如下:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.usafootball.rulesapp.R;
import com.usafootball.rulesapp.customfont.TextViewPlus;

public class AboutThisAppFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View mView = inflater.inflate(R.layout.about,
                container, false);
        TextViewPlus textViewPlus = (TextViewPlus) mView.findViewById(R.id.textViewAboutUSAF);
        textViewPlus.setText(Html.fromHtml(getString(R.string.AboutThisApp)));

        return mView;
    }

}

为了更清楚地显示数据,但它以段落 NOT LIST 的形式出现。任何建议如何做到这一点......

4

2 回答 2

2

AFAIK <ul><li>标签不受支持TextView,这就是它不起作用的原因。在此处查看支持的标签列表:TextView 支持的 HTML 标签

于 2013-09-16T15:45:01.860 回答
0
1. TextView not support all html tag.
2. Use WebView rather than TextView.

**layoutname.xml**
<WebView
   android:id="@+id/webview"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"/>

**string.xml**
<string name="AboutThisApp">&lt;div>
    &lt;p>here is the list of functions: &lt;/p>
&lt;/div>

&lt;ul>
    &lt;li> Sportsmanship&lt;/li>
    &lt;li> Participation&lt;/li>
    &lt;li> Safety/Risk Minimization&lt;/li>
    &lt;li> Sound Traditions of the Sport&lt;/li>
    &lt;li> Support for USA Footvall\'s Mission&lt;/li>
    &lt;li> Balance Between Offense and Defence&lt;/li>
    &lt;/ul>

</string>

**activity**
 private WebView webview;
 // write below code in onCreate()
 webview = (WebView) findViewById(R.id.webview);
 webview.loadData(getString(R.string.AboutThisApp),"text/html","utf-8");
于 2013-09-18T06:35:01.137 回答