2017-02-12 151 views
0

我在Horizo​​ntalScrollView中有Listview。該列表視圖保存文件路徑,水平滾動視圖旨在消除包裝較長路徑的需要。Android ListView切斷比第一項更寬的項目

所有的工作都完全按照需要進行,除了在第一個項目的長度上,比第一個項目更長的任何項目被剪切(不管第一個項目的寬度是多少,其他項目都不會滾過那個寬度)。

這是給我找麻煩佈局的部分:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/layoutListView" 
    android:orientation="vertical" 
    android:layout_below="@+id/spFileTypes"> 

    <HorizontalScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <ListView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/lvItems"/> 

    </HorizontalScrollView> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="" 
     android:id="@+id/tvStatus"/> 

</LinearLayout> 

這是問題的一個截圖:

listview issue screenshot

圖片一路滾動到對。第三項是切斷「.php」。我已經嘗試過使用長短文件名,很多(上面的兩位數字)列表以及幾個列表,在每種情況下,寬度限制似乎取決於第一項的寬度。

每當列表發生變化時,它總是限制其寬度,無論第一個元素是什麼。

希望的行爲是讓它匹配最寬項目的寬度。

我把我的心挖出來,通過官方文檔挖出來,我很難過。任何幫助是極大的讚賞:)

+0

Horizo​​ntalScrollView的layout_weight = 1,而LinearLayout中的第二個孩子沒有。您應該將權重添加到TextView或從ListView中刪除它。希望它是幫助。 –

+0

我會記下這一點,但TextView完全按照需要顯示在屏幕上(屏幕截圖只是爲了顯示特定的切斷行爲) – BMB

回答

0

而是包裹在Horizo​​ntalScrollView ListView中的,試試這個:

<ListView 
    android:id="@+id/listview" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="horizontal"/> 

如果這可以幫助任何人,那麼請投我的答案。謝謝。

+0

是的,列表視圖不應該是任何滾動視圖的子視圖。它可能會導致奇怪的行爲。 –

+0

不知道爲什麼,但是當我將代碼更改爲該代碼時,它將包裝這些字符串,使它們有點難以閱讀。我沒有得到屏幕上的任何滾動條(我假設,因爲他們包裝?)這可能是TextView的每個單獨的列表項的問題? – BMB