0

我見過很多與我有關的問題,但是,這些都沒有工作。我目前正在設計一個視圖,在ScrollView中有四個ListView,並且我想讓整個ScrollView滾動,同時顯示ListView中的所有項目。這不是問題;然而,列表視圖與我的headertexts不同列表視圖重疊。ScrollView中的ListViews與我的TextViews重疊

我已經嘗試使用邊距和填充;沒有誰工作。我也試圖將scrollLayout重新轉換爲LinearLayout。我也嘗試將文本放在單獨的LinearLayouts中,與ListView分開,但這也不起作用。

以下是我的src代碼。有誰知道如何使文本不與ListViews中的頂部項目重疊?順便說一句,「頂部結果」,上面的一個,完全正常。

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/scrollView" 
    android:layout_alignParentTop="true"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/scrollLayout"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/topResultLayout"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/topResultTitle" 
       android:textSize="20sp" 
       android:textIsSelectable="false" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:textColor="#000000" /> 

      <ListView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/topResultList" 
       android:layout_below="@id/topResultTitle"/> 

     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      android:layout_centerHorizontal="true" 
      android:id="@+id/streamResultLayout" 
      android:layout_below="@id/topResultLayout"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/streamResultTitle" 
       android:textSize="20sp" 
       android:textIsSelectable="false" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:textColor="#000000" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/seeAllStreams" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:textColor="#000000" 
       android:textSize="14sp" 
       android:layout_above="@+id/streamResultList" /> 





      <ListView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/streamResultList" 
       android:layout_below="@id/streamResultTitle"/> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      android:layout_centerHorizontal="true" 
      android:id="@+id/broadcasterResultLayout" 
      android:layout_below="@id/streamResultLayout"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/broadcasterResultTitle" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:textSize="20sp" 
       android:textIsSelectable="false" 

       android:textColor="#000000" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/seeAllBroadcasters" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 

       android:textColor="#000000" 
       android:textSize="14sp" /> 




      <ListView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/broadcasterResultList" 
       android:layout_below="@id/broadcasterResultTitle"/> 
     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      android:layout_centerHorizontal="true" 
      android:id="@+id/tagResultLayout" 
      android:layout_below="@id/broadcasterResultLayout" 
      android:layout_alignParentBottom="true"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/tagResultTitle" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:textSize="20sp" 
       android:textIsSelectable="false" 
       android:textColor="#000000" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/seeAllTags" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:textColor="#000000" 
       android:textSize="14sp" /> 




      <ListView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/tagResultList" 
       android:layout_below="@id/tagResultTitle"/> 
     </RelativeLayout> 
    </RelativeLayout> 
</ScrollView> 

+1

切勿使用內部''ScrollView'和ListView'反之亦然 – GVillani82

+0

的ListView自身滾動還挺查看 –

+0

好看起來不錯XML明智的,我認爲,你在用什麼擴展它?我使用下面的代碼。 –

回答

1
public static void setListViewHeightBasedOnChildren(ListView listView, ListAdapter adapter) 
    { 
     ListAdapter listAdapter = adapter; 

     if (listAdapter == null) { 
      return; 
     } 

     int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED); 
     int totalHeight = 0; 
     View view = null; 
     for (int i = 0; i < listAdapter.getCount(); i++) { 
      view = listAdapter.getView(i, view, listView); 
      if (i == 0) { 
       view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); 
      } 
      view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); 
      totalHeight += view.getMeasuredHeight(); 
     } 
     ViewGroup.LayoutParams params = listView.getLayoutParams(); 
     params.height = totalHeight; 
     listView.setLayoutParams(params); 
     listView.requestLayout(); 
    } 
+0

謝謝,這確實像魅力一樣工作。但仍然有一些問題。它僅顯示第一個ListView的三個項目之一,即streamResultList。你也許知道是什麼原因造成的?此外,最後一個仍然沒有工作,所以我添加了20dp的填充頂部,並且tagResultLayout中的TextViews和ListView分開了。但是,tagResultList中最後一項的一小部分消失了。我可以在你的函數的ListView中添加一些空間嗎?也許在循環中,像if(i == listAdapter.getCount())? – Filip

+0

我現在解決了第一個問題,所以我看到了所有的流。但是,在上一節中單擊seeAll仍然無效。填充使得不可能點擊它unfortunatley,即使填充修復佈局問題。你知道如何解決這個問題嗎?非常感謝你的幫助btw! – Filip