我正在编写一个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的代码以适应我的问题。
有人可以帮我吗?
答案 0 :(得分:0)
Raybritton是对的。您不能让ListView和Web视图共享相同的滚动条。你不能嵌套滚动视图。
您需要做的是创建一个ListView适配器。这样,您就可以为列表的每一行创建自定义视图。
请按照以下示例: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
然后在布局中放置一个WebView,并将其可见性设置为“Gone”。当您准备好显示它时,在代码中将其设置为“可见”。说明ListView只有2行。这两行将共享相同的布局,但您可以在此处指定每个项目的单独可见性,以使行看起来不同。
这么长的故事简短:熟悉ListView适配器和隐藏视图。
希望有意义!