Android - 滚动后Webview高度增加

时间:2015-07-13 12:26:04

标签: java android android-listview scrollview listitem

我正在开发一个Android应用程序,其中我使用webview而不是Textview在每个列表项上使用 justify 属性。

list_item.xml

10:00:00

CustomListAdapter.java

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:orientation="vertical" android:padding="10dp" > <WebView android:id="@+id/question" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="Question" android:textSize="20sp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="@color/color_black"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:weightSum="2" > <TextView android:id="@+id/select_yes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="Yes" android:textSize="30sp" /> <TextView android:id="@+id/select_no" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="No" android:textSize="30sp" /> </LinearLayout> </LinearLayout>

getView()

如果我运行该应用程序,请enter image description here

但是,在我更改滚动位置后再次转到上一个位置。 webview的高度增加如下,

enter image description here

注意: String question = "<html><body>" + "<p align=\"justify\">" + data.get(position).getStudyCrit() + "</p> " + "</body></html>"; holder.question.loadData(question, "text/html", "utf-8"); 没有问题,当我用TextView

替换TextView时出现了问题

请帮我找到解决方案。

2 个答案:

答案 0 :(得分:1)

您可以使用TextView而不是WebView,在TextView中可以设置如下文本:

textView.setText(Html.fromHtml(question));

您可以为TextView定义maxLines。

答案 1 :(得分:0)

您不需要仅使用webview来证明内容的合理性。您可以使用以下代码:

String question = "<html><body>"

        + "<p align=\"justify\">"

        + data.get(position).getStudyCrit()

        + "</p> "

        + "</body></html>";
yourtextview.setText(Html.fromHtml(question));
相关问题