A ListView under a WebView

扶醉桌前 提交于 2019-12-11 09:28:04

问题


I am writing an Android app to display a forum. The content of the main article is in a WebView, and I'd like to put the answers into a ListView under the main article.

<?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="fill_parent"
    android:background="@drawable/bg"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        //android:layout_weight="1.0"
        android:background="@drawable/bg"
        android:cacheColorHint="#00000000"
        android:textColor="#FFDEC2" />

    <ListView

        android:id="@+id/contentlist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

Here the ListView isn't displayed at all. If I enable

android:layout_weight="1.0"

the screen gets split, both are shown, but the ListView should be under the WebView, so that there is just one scrollbar for both.

I think this article: Android layout - listview and edittext below is about my problem, but I don't understand how to edit the code of this site to fit to my problem.

Can anyone help me please?


回答1:


Raybritton is correct. You cannot have a ListView and a Web view share the same scrollbar. You cant nest scrollviews.

What it sounds like you will need to do is create a ListView adapter. This way you can create a custom view for each row of the list.

Follow this example: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

Then place a WebView inside the layout and set its visibility to "Gone". When you are ready to have it appear set it to "Visible" in the code. State that the ListView only has 2 rows. Both rows will share the same layout, but this is where you specify the individual visibility of each item to make the rows look different.

So long story short: become familiar with ListView adapters and hiding views.

Hope that makes sense!



来源:https://stackoverflow.com/questions/8152071/a-listview-under-a-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!