0

我在Scrollview的內部有一個LinearLayout。做了一些動畫之後,當我向下滾動時,底部有空白區域。所以,我想使用此代碼無法調整LinearLayout的高度

   ViewGroup.LayoutParams params = _linearLayoutMainWrapper.getLayoutParams(); 
       params.height = 100; 
       _linearLayoutMainWrapper.setLayoutParams(params); 

它不工作,雖然,只是什麼也沒發生,以調整LinearLayout。當我嘗試調整width時,它正在工作。

的XML是

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:animateLayoutChanges="true" 
    android:fillViewport="true" 
    android:id="@+id/scrollViewMain"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:animateLayoutChanges="true" 
     android:orientation="vertical" 
     android:paddingLeft="16dip" 
     android:paddingRight="16dip" 
     android:id="@+id/linearLayoutMainWrapper"> 

     <!-- a lot of stuff --> 

    </LinearLayout> 

</ScrollView> 
+0

你可以顯示你的「_linearLayoutMainWrapper」xml佈局。有時錯誤在於屬性,例如在某些情況下,將高度設置爲wrap_content會阻止您在稍後更改高度。 – AmiNadimi

+0

爲什麼在LinearLayout上不使用android:layout_height =「wrap_content」?你的佈局總是從scrollview中獲得高度。也許嘗試編輯scrollview的高度或將linearlayout高度屬性更改爲wrap_content。 –

+0

我做了,它沒有工作,所以我改變了它,因爲上面的評論說「wrap_content」會導致問題。它仍然沒有工作。 –

回答

0

也許你有一些餘量爲設置好的這個觀點?嘗試清除params邊界,LinearLayout的height應該是youScrollView.getMeasuredHeight()

+0

您的意思是?我正在執行動畫的那個?這是許多意見之一,我隱藏向上翻譯「在另一種觀點」 感謝與.getMeasuredHeight()雖然 –

+0

提示技巧'視圖'可能是LinearLayout - 邊距或滾動視圖 - 填充。你正在執行什麼動畫? – kenzo