1

我有一个活动,屏幕的主要区域是 2 个列表视图。一个高于另一个。单击顶部列表视图中的项目会更改下部列表视图中显示的内容。

问题是我似乎无法强制每个列表始终使用 1/2 的可用空间。如果顶部列表有 100 个项目,底部有 1 - 底部列表完全消失,顶部列表占用所有空间。

我在这里读过几个类似的问题 - 他们似乎都说只需将 ListView 包装在他们自己的 LinearLayouts 中就可以了。不适合我。如果底部列表中只有几个项目,它仍然会缩小或消失。

这是我的xml:

  DELETED old XML due to posting size limit.

所以,我尝试了第一个建议 - 这不起作用。仅当列表中的项目数大致相似时,列表的大小才会相同。如果一个列表有 100 个项目,而另一个有 3 个,则 3 个项目的列表占用的屏幕空间要少得多。此外,如果两个列表都相对较短,它们甚至不会填满屏幕,并在底部留下一个空白区域。请注意,此屏幕中还有其他必需的控件,其中一些根据需要变为可见/消失。

这是更新的 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF000000"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <com.teamunify.ondeck.widget.TUButton
                android:id="@+id/prevButton"
                style="@style/prevButton"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_weight="0.5"
                android:onClick="onPrevResult" />

            <com.teamunify.ondeck.widget.TUTextView
                android:id="@+id/meet_name"
                style="@style/sans.white.16.bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_weight="1.0"
                android:ellipsize="end"
                android:gravity="center_horizontal"
                android:paddingTop="4dp"
                android:singleLine="true"
                android:text="@string/example_meet_name_long" />

            <com.teamunify.ondeck.widget.TUButton
                android:id="@+id/nextButton"
                style="@style/nextButton"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_weight="0.5"
                android:onClick="onNextResult" />
        </LinearLayout>

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:padding="6dp" >

            <com.teamunify.ondeck.widget.TURadioButton
                android:id="@+id/filter_mine"
                style="@style/sans.white.14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:background="@drawable/grey_segment_left"
                android:button="@drawable/small_crap"
                android:gravity="center"
                android:onClick="onFilterMine"
                android:text="@string/my_kids" />

            <com.teamunify.ondeck.widget.TURadioButton
                android:id="@+id/filter_team"
                style="@style/sans.white.14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:background="@drawable/grey_segment_mid"
                android:button="@drawable/small_crap"
                android:gravity="center"
                android:onClick="onFilterTeam"
                android:text="@string/my_team" />

            <com.teamunify.ondeck.widget.TURadioButton
                android:id="@+id/filter_all"
                style="@style/sans.white.14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:background="@drawable/grey_segment_right"
                android:button="@drawable/small_crap"
                android:checked="true"
                android:gravity="center"
                android:onClick="onFilterAll"
                android:text="@string/all" />
        </RadioGroup>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <com.teamunify.ondeck.widget.TUButton
                android:id="@+id/search_button"
                style="@style/searchButton"
                android:layout_margin="4dp"
                android:gravity="center"
                android:onClick="onSearch" />

            <RadioGroup
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1.0"
                android:gravity="center_horizontal"
                android:orientation="horizontal" >

                <com.teamunify.ondeck.widget.TURadioButton
                    android:id="@+id/filter_events"
                    style="@style/sans.white.14"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:background="@drawable/grey_segment_left"
                    android:button="@drawable/small_crap"
                    android:gravity="center"
                    android:onClick="onFilterEvents"
                    android:text="@string/events" />

                <com.teamunify.ondeck.widget.TURadioButton
                    android:id="@+id/filter_swimmers"
                    style="@style/sans.white.14"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:background="@drawable/grey_segment_right"
                    android:button="@drawable/small_crap"
                    android:checked="true"
                    android:gravity="center"
                    android:onClick="onFilterSwimmers"
                    android:text="@string/swimmers" />
            </RadioGroup>

            <com.teamunify.ondeck.widget.TUButton
                android:id="@+id/help_button"
                style="@style/helpButton"
                android:layout_margin="4dp"
                android:gravity="center"
                android:onClick="showHelp" />
        </LinearLayout>
    </LinearLayout> <!-- end of heading -->

    <LinearLayout
        android:id="@+id/tophdr_event"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:layout_weight="0"
        android:background="#FF000000"
        android:orientation="horizontal" >

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_filter_gender"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onFilterGender"
            android:paddingLeft="5dp"
            android:text="@string/gender" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_filter_distance"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onFilterDistance"
            android:paddingLeft="5dp"
            android:text="@string/distance" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_filter_stroke"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onFilterStroke"
            android:paddingLeft="10dp"
            android:text="@string/stroke" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_filter_age"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onFilterAge"
            android:paddingLeft="26dp"
            android:text="@string/age" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/tophdr_swimmer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:layout_weight="0"
        android:background="#FF000000"
        android:orientation="horizontal"
        android:visibility="gone" >

        <com.teamunify.ondeck.widget.TUTextView
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:gravity="center_vertical"
            android:paddingLeft="16dp"
            android:text="@string/swimmer" />

        <com.teamunify.ondeck.widget.TUTextView
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:gravity="center_vertical"
            android:paddingLeft="16dp"
            android:text="@string/event_age" />

        <com.teamunify.ondeck.widget.TUTextView
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:gravity="center_vertical"
            android:paddingLeft="16dp"
            android:text="@string/team" />
    </LinearLayout>

    <ListView
        android:id="@+id/meet_result_top_list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="2dp"
        android:layout_weight="0.5"
        android:background="#FF333333" />

    <com.teamunify.ondeck.widget.TUTextView
        android:id="@+id/meet_result_top_empty"
        style="@style/sans.white.18.bold"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:background="#FF333333"
        android:gravity="center"
        android:text="@string/no_matching_data"
        android:visibility="gone" />

    <LinearLayout
        android:id="@+id/bothdr_event"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:layout_weight="0"
        android:background="#FF000000"
        android:orientation="horizontal"
        android:visibility="gone" >

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_event"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortEvent"
            android:paddingLeft="16dp"
            android:text="@string/event" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_evpos"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortPos"
            android:paddingLeft="16dp"
            android:text="@string/position" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_evpoints"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortPointsE"
            android:paddingLeft="16dp"
            android:text="@string/points" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_evtime"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortTimeE"
            android:paddingLeft="16dp"
            android:text="@string/time" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bothdr_swimmer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:layout_weight="0"
        android:background="#FF000000"
        android:orientation="horizontal" >

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_swimmer"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortSwimmer"
            android:paddingLeft="5dp"
            android:text="@string/swimmer" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_team"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortTeam"
            android:paddingLeft="14dp"
            android:text="@string/team" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_swpos"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortEvent"
            android:paddingLeft="25dp"
            android:text="@string/position" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_swpoints"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortPointsS"
            android:paddingLeft="4dp"
            android:text="@string/points" />

        <com.teamunify.ondeck.widget.TUButton
            android:id="@+id/btn_sort_swtime"
            style="@style/sans.white.12"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:drawableRight="@drawable/filter"
            android:gravity="center_vertical"
            android:onClick="onSortTimeS"
            android:paddingLeft="4dp"
            android:text="@string/time" />
    </LinearLayout>

    <ListView
        android:id="@+id/meet_result_bot_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:layout_weight="0.5"
        android:background="#FF333333"
        android:visibility="visible" >
    </ListView>

    <com.teamunify.ondeck.widget.TUTextView
        android:id="@+id/meet_result_bot_empty"
        style="@style/sans.white.18.bold"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="0.5"
        android:background="#FF333333"
        android:gravity="center"
        android:text="@string/meet_manage:no_entries"
        android:visibility="gone" />

</LinearLayout>
4

1 回答 1

1

它应该有这样的形式:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5" />

</LinearLayout>
于 2013-08-01T22:49:29.607 回答