WebView作为ListView行不能正确滚动

时间:2011-12-20 14:57:35

标签: android webview scroll textview

我正在尝试制作一个ListView,它应该像股票消息传递应用程序或GTalk那样。它显示了两个人之间的对话。 WebView负责显示会话的HTML文字包含几个gif动画(表情符号 - TextView无法显示)显然,当新邮件到达时,列表必须一直滚动到底部(我正在使用listview.setSelection(...)
现在,如果WebView的高度超过正常值,则ListView会混乱并滚动到靠近列表末尾的项目而不是最后一项。就像我说的,我认为这个列表在计算它的孩子的高度时有问题。 (已在文档提及的smoothScroll上停用了ListView

用作ListView

中的行的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" android:background="#f7f7f7">

    <ImageView
        android:id="@+id/imgFriendAvatarChat"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        />

    <WebView
        android:id="@+id/friendMessageWebView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginRight="5dp"
        />

</LinearLayout>

我对thisthis没有任何有用的答案,我正在使用最后一个解决方案,这是一个令人讨厌的行为,然后我接吻Android再见! (你可以猜到,我已经厌倦了Android阻碍了开发的各个方面。)

解决方案使用WebView作为ListView行来显示我想要的内容。问题是,如果WebView的内容是3行,那么ListView会变得疯狂,并且不会正确滚动到列表的底部。我的猜测是,它无法计算每个子行的高度,并错误地导航到列表的中间而不是它的底部。

我已经阅读了太多类似的问题,例如this,我没有得到很好的答复......

1 个答案:

答案 0 :(得分:0)

问题是webview在创建时没有大小,并且只有在webview加载并渲染内容后才测量高度有效,这对于listview计算大小来说通常为时已晚。  您是否考虑过修改布局的高度? 如何不使用listview而不是一个大的webview?