1

我有一個活動,其中屏幕的主區域是2個列表視圖。一個在另一個之上。 單擊頂部列表視圖中的項目會更改在下部列表視圖中顯示的內容。在同一屏幕上製作2個Android ListViews的高度相同

問題是,我似乎無法強迫每個列表總是使用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> 

回答

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> 
+0

見上面我的更新XML。 另請注意,大多數其他時間都是這樣問的,XML的確切格式已失敗。 – CasaDelGato

相關問題