inearLayout内滚动型distrubing的ListVi

inearLayout内滚动型distrubing的ListVi

本文介绍了的LinearLayout内滚动型distrubing的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的LinearLayout whcih包含按钮和列表视图。越来越多的按钮后,我决定把该LinearLayout中成滚动型,但我的列表视图都出现了只有一个项目将滚动型后

I have LinearLayout whcih contains Buttons and ListViews. After getting many buttons and I decide to put that LinearLayout into ScrollView but after putting ScrollView my ListViews are showing only one Item.

以下是滚动型前的$​​ C $ C

Following is the code before ScrollView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".WorkplaceObservationActivity" >

    <Button
        android:id="@+id/btn_reportType"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Report Type" />

    <ListView
        android:id="@+id/lv_reportType"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" >
    </ListView>

    <Button
        android:id="@+id/btn_defineJob"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Define Job" />

    <ListView
        android:id="@+id/lv_Jobs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:checkMark="?android:attr/listChoiceIndicatorMultiple"
        android:visibility="gone" >
    </ListView>

    <Button
        android:id="@+id/btn_timeLocation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Time and Location" />

    <LinearLayout
        android:id="@+id/ll_timeLocation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone" >

        <Button
            android:id="@+id/btn_setCurrentTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="Use current time and date" />

        <Button
            android:id="@+id/btn_setCustomTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="Enter custom time" />

        <Button
            android:id="@+id/btn_setCustomDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="Enter custom date" />

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Time and Date: "
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:visibility="gone" />
    </LinearLayout>

    <Button
        android:id="@+id/btn_ReportDetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Report Details" />

    <LinearLayout
        android:id="@+id/ll_ReportDetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone" >

        <Button
            android:id="@+id/btn_CaptureVideo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Capture Video" />

        <ListView
            android:id="@+id/lv_ReportDetailsItems"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >
        </ListView>
    </LinearLayout>

    <Button
        android:id="@+id/btn_Review"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Review" />

    <LinearLayout
        android:id="@+id/ll_Review"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv_Review_ReportType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Report Type: "
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/tv_Review_DateTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date and Time: "
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/tv_Review_SupportingFiles"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Supporting Files: "
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <ListView
            android:id="@+id/lv_ReviewItems"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:visibility="gone" >
        </ListView>

        <Button
            android:id="@+id/btn_Review_Send"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Send" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2" >

            <Button
                android:id="@+id/btn_Review_Save"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Save Draft" />

            <Button
                android:id="@+id/btn_Review_Discard"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Discard" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

以上code我得到下面的屏幕截图

for Above Code I am getting Following Screen Shot

以下是滚动型之后的XML code

Following is the xml code after ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".WorkplaceObservationActivity" >

        <Button
            android:id="@+id/btn_reportType"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Report Type" />

        <ListView
            android:id="@+id/lv_reportType"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone" >
        </ListView>

        <Button
            android:id="@+id/btn_defineJob"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Define Job" />

        <ListView
            android:id="@+id/lv_Jobs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:visibility="gone" >
        </ListView>

        <Button
            android:id="@+id/btn_timeLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Time and Location" />

        <LinearLayout
            android:id="@+id/ll_timeLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone" >

            <Button
                android:id="@+id/btn_setCurrentTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:text="Use current time and date" />

            <Button
                android:id="@+id/btn_setCustomTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:text="Enter custom time" />

            <Button
                android:id="@+id/btn_setCustomDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:text="Enter custom date" />

            <TextView
                android:id="@+id/tv_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Time and Date: "
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:visibility="gone" />
        </LinearLayout>

        <Button
            android:id="@+id/btn_ReportDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Report Details" />

        <LinearLayout
            android:id="@+id/ll_ReportDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone" >

            <Button
                android:id="@+id/btn_CaptureVideo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Capture Video" />

            <ListView
                android:id="@+id/lv_ReportDetailsItems"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" >
            </ListView>
        </LinearLayout>

        <Button
            android:id="@+id/btn_Review"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Review" />

        <LinearLayout
            android:id="@+id/ll_Review"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tv_Review_ReportType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Report Type: "
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/tv_Review_DateTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Date and Time: "
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/tv_Review_SupportingFiles"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Supporting Files: "
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <ListView
                android:id="@+id/lv_ReviewItems"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:visibility="gone" >
            </ListView>

            <Button
                android:id="@+id/btn_Review_Send"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Send" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="2" >

                <Button
                    android:id="@+id/btn_Review_Save"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Save Draft" />

                <Button
                    android:id="@+id/btn_Review_Discard"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Discard" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</ScrollView>

和以下是上述

我要显示滚动型之后的项目的完整列表。

I want to show complete list of items after scrollview.

推荐答案

目前的滚动型的ListView 。一般情况下,你不能把一个的ListView 滚动型的ListView 已了解有关滚动,将滚动本身。 的ListView 需要知道如何在屏幕上多的垂直空间,应该使用,使之能够控制其子的滚动和显示。这是很难明白,你已经发布的布局应该怎样做人。

There is a conflict between the ScrollView and the ListView. In general, you cannot put a ListView inside a ScrollView. ListView already understands about scrolling and will scroll itself. ListView needs to know how much vertical space on the screen it should use, so that it can control the scrolling and display of its children. It is difficult to understand how the layout that you've posted should behave.

在任何情况下,只有这样,才能把的ListView 滚动型是告诉的ListView 应该到底有多少垂直空间使用。不能使用 match_parent WRAP_CONTENT layout_height ,您需要以固定垂直尺寸。这有助于滚动型来确定多少垂直空间的每个子进程占用,然后滚动型可以做正确的事情。

In any case, the only way to put a ListView inside a ScrollView is to tell the ListView exactly how much vertical space it should use. You cannot use match_parent or wrap_content for layout_height, you need to fix the vertical size. This helps the ScrollView to determine how much vertical space each of its children takes up, and then the ScrollView can do the right thing.

尝试设置机器人:在您所有的的ListView 取值layout_height =80dp来看看如何表现。

Try setting android:layout_height="80dp" on all of your ListViews to see how this behaves.

编辑:以后再看的布局,我还有一个建议

在再看的布局,我假设你想有(只有一个有形之在给定时间的的ListView 其他人都将是 GONE )。在这种情况下,你可以尝试以下操作:

After looking at the layout again, I am assuming that you want to have only one of the ListViews visible at a given time (the others would all be GONE). In this case, you might try the following:

  1. 删除周边滚动型
  2. 设置的android:layout_weight =1安卓layout_height =1px的上的所有的ListView 取值
  1. Remove the surrounding ScrollView
  2. Set android:layout_weight="1" and android:layout_height="1px" on all ListViews

这基本上是告诉布局管理器的的ListView 应给予在屏幕上的所有可用空间(即:无论是在其他以后遗留下来的查看 s的布局)。这将使的ListView 扩展为占用屏幕上的所有可用空间,同时保持所有其他查看 S上屏幕,整个屏幕不会滚动,只有的ListView 。这可能是一个更好的办法,你要什么给你。

This basically tells the layout manager that the ListView should be given all available space on the screen (ie: whatever is left over after the other Views are laid out). This will make the ListView expand to take up all available space on the screen, while keeping all the other Views on screen and the entire screen will not scroll, only the ListView. This may be a better way to give you what you want.

您也可以考虑使用 ExpandableListView ,这似乎是你想在这里重新什么。

You might also consider using ExpandableListView, which seems to be what you are trying to recreate here.

这篇关于的LinearLayout内滚动型distrubing的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:53