Android ScrollView高度太短

问题描述:

我是Android的新手,有这个问题,使滚动视图应该滚动到10+项目的ListView上。Android ScrollView高度太短

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="com.naqishop.naqi.MainActivity" 
     tools:showIn="@layout/activity_main"> 


     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/scrollView"> 

     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/listView" 
      android:entries="@array/options" /> 


     </ScrollView> 



</LinearLayout> 

问题是我无法扩展滚动视图来一次显示多个项目。我试着用滚动视图的layout_height篡改(如分配值500dp) 我也尝试添加

android:fillViewport="true" 

为suggestd here 但它并没有改变高度。所以感谢你的提示。

+1

您无法使用'android:layout_height =“wrap_content”'ScrollView' :-( 将其设置为android:layout_height =“match_parent”“' –

+1

您不需要ScrollView。它只是使用ListView它包含滚动里面 –

+0

@MichaelKatkov好点,谢谢! – Karlom

这是因为你已经设置了android:layout_height="wrap_content"。用 android:layout_height="match_parent"代替它,它将占据整个高度。