在 LinearLayout 中显示整个 ListView

发布于 2024-12-17 07:44:04 字数 1450 浏览 6 评论 0原文

我尝试将 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项目。

我在 LinearLayoutWebView< 中尝试了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酉 2024-12-24 07:44:04

您应该使用布局权重。这是一种使用百分比来定义布局的方法。

在以下示例中,ListView 使用 60% 的空间,WebView 使用 40% :

<LinearLayout
    android:id="@+id/main_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:weightSum="1.0" >

    <WebView
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:textColor="#FFDEC2"
        android:layout_weight=".40" />

    <ListView
        android:id="@+id/comments"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".60" >
    </ListView>
</LinearLayout>

只需将这些百分比更改为您想要的任何值即可。

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% :

<LinearLayout
    android:id="@+id/main_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:weightSum="1.0" >

    <WebView
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:textColor="#FFDEC2"
        android:layout_weight=".40" />

    <ListView
        android:id="@+id/comments"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".60" >
    </ListView>
</LinearLayout>

Just change these percentages to whatever you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文