在 LinearLayout 中显示整个 ListView
我尝试将 ListView
放置在 WebView
下,为此,我使用以下 xml 代码:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg"
android:orientation="vertical"
android:scrollbars="vertical" >
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:textColor="#FFDEC2" />
<ListView
android:id="@+id/comments"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</ScrollView>
该代码显示 WebView
的内容,并且ListView
正确,但 ListView
的高度仅为 ListView
Item 的 1.5 倍左右,因此不会显示整个 List,而仅显示第一个 List项目。
我在 LinearLayout
、WebView< 中尝试了
android:layout_height="fill_parent"
和 android:layout_height="wrap_content"
的几种组合/code>、ListView
和周围的 ScrollView
,它们都不起作用。
I try to place a ListView
under a WebView
, to do this I use the folloing xml code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg"
android:orientation="vertical"
android:scrollbars="vertical" >
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:textColor="#FFDEC2" />
<ListView
android:id="@+id/comments"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</ScrollView>
The code displays the content of the WebView
and ListView
correctly, but the ListView
just has the high of about 1.5 times the ListView
Item, so not the entire List is displayed but just the first Items.
I tried several combinations of android:layout_height="fill_parent"
and android:layout_height="wrap_content"
in the LinearLayout
, WebView
, ListView
and the surrounding ScrollView
, none of them worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用布局权重。这是一种使用百分比来定义布局的方法。
在以下示例中,ListView 使用 60% 的空间,WebView 使用 40% :
只需将这些百分比更改为您想要的任何值即可。
You should use layout weights. It's a way to use percentages to define your layout.
In the following example, the ListView uses 60% of the space, and the WebView 40% :
Just change these percentages to whatever you want.