【问题标题】:A ListView under a WebViewWebView下的ListView
【发布时间】:2012-04-13 06:30:19
【问题描述】:

我正在编写一个 Android 应用程序来显示一个论坛。 主文的内容在WebView,我想把答案放到主文下的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="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>

这里根本不显示ListView。如果我启用

android:layout_weight="1.0"

屏幕被分割,两者都显示了,但ListView 应该在WebView 之下,因此两者只有一个滚动条。

我认为这篇文章:Android layout - listview and edittext below 是关于我的问题,但我不明白如何编辑此 site 的代码以适应我的问题。

谁能帮帮我?

【问题讨论】:

  • 您不能在滚动视图中使用列表视图,反之亦然。

标签: android listview layout webview forum


【解决方案1】:

雷布里顿是正确的。您不能让 ListView 和 Web 视图共享同一个滚动条。你不能嵌套滚动视图。

听起来您需要做的是创建一个 ListView 适配器。这样您就可以为列表的每一行创建一个自定义视图。

按照这个例子: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

然后在布局内放置一个 WebView 并将其可见性设置为“Gone”。当您准备好让它出现时,在代码中将其设置为“可见”。声明 ListView 只有 2 行。两行将共享相同的布局,但您可以在此处指定每个项目的单独可见性以使行看起来不同。

长话短说:熟悉 ListView 适配器和隐藏视图。

希望这是有道理的!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    相关资源
    最近更新 更多