2016-08-31 42 views
1

Scrollview留出空間在某些layouts我是新至Android請幫幫這裏是我的代碼:滾動視圖留下多餘的空間佈局,在活動的底部

<ScrollView  
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollviewdb"  
    android:layout_width="match_parent"  
    android:layout_height="wrap_content" > 
    <LinearLayout  
     xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical"  
       android:layout_width="match_parent"  
       android:layout_height="wrap_content">  
     <TextView   
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"   
      android:textSize="15sp" 
      android:padding="5dp"  
      android:id="@+id/ghavaed_text"/> 
     </LinearLayout> 
    </ScrollView> 
+1

add screenshot..so people can help you .. –

+1

歡迎來到Stack Overflow!請參考[遊覽](http://stackoverflow.com/tour),環顧四周,閱讀[幫助中心](http://stackoverflow.com/help),特別是[我該如何問一個好問題?](http://stackoverflow.com/help/how-to-ask) – Squazz

+0

在滾動視圖中使用android:fillViewport =「true」 –

回答

2

添加android:fillViewport在滾動型。

<ScrollView  
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollviewdb"  
    android:fillViewport="true" 
    android:layout_width="match_parent"  
    android:layout_height="wrap_content" > 
    <LinearLayout  
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content">  
     <TextView   
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"   
      android:textSize="15sp" 
      android:padding="5dp"  
      android:id="@+id/ghavaed_text"/> 
    </LinearLayout> 
</ScrollView> 

正如@Ironman解釋的那樣,如果ScrollView的內容總是和自身一樣高,那麼它將變得毫無用處。要解決此問題,您需要使用名爲android:fillViewport的ScrollView屬性。如果設置爲true,則此屬性會導致滾動視圖的子級擴展到ScrollView的高度(如果需要)。當孩子比ScrollView高時,屬性沒有效果

+1

我給+1給你,因爲你的答案是正確的,但你必須添加解釋說,如果ScrollView的內容總是和自身一樣高,那麼它將變得毫無用處。要解決此問題,您需要使用名爲android:fillViewport的ScrollView屬性。如果設置爲true,則此屬性會導致滾動視圖的子級擴展到ScrollView的高度(如果需要)。當孩子比ScrollView高,屬性沒有效果' – Ironman

+0

fillViewport沒有工作我試過@Ironman –

+0

它不能解決fillViewport :(@MahfuzIslamBhuiyan –

相關問題