2016-03-10 112 views
0

我有一個XML佈局,由七個textview和spinners組成,在spinners和textview下我有一個導致問題的列表視圖。列表視圖設置爲包裝內容,但它只有1行的高度,無論我給它的重量或身高是多少,它都保持相同的大小。Android列表視圖有限高度

有人能指出我要去哪裏嗎?

XML

<android.support.v4.widget.DrawerLayout 
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:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<!-- The main content view --> 

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout2"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    </android.support.design.widget.AppBarLayout> 

    <ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="?actionBarSize" 
     android:paddingBottom="?actionBarSize"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/monday" 
     android:text="Monday's Recipe: " 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
    <TextView 
     android:id="@+id/mondayRecipe" 
     android:layout_toRightOf="@+id/monday" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
    </RelativeLayout> 

     <Spinner 
     android:id="@+id/mondaySpinner" 
     android:layout_below="@+id/monday" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"></Spinner> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/tuesday" 
       android:text="Tuesday's Recipe: " 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <TextView 
       android:id="@+id/tuesdayRecipe" 
       android:layout_toRightOf="@+id/tuesday" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" /> 
     </RelativeLayout> 

     <Spinner 
      android:id="@+id/tuesdaySpinner" 
      android:layout_below="@+id/tuesday" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"></Spinner> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/wednesday" 
       android:text="Wednesday's Recipe: " 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <TextView 
       android:id="@+id/wednesdayRecipe" 
       android:layout_toRightOf="@+id/wednesday" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
     </RelativeLayout> 

     <Spinner 
      android:id="@+id/wednesdaySpinner" 
      android:layout_below="@+id/wednesday" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"></Spinner> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/thursday" 
       android:text="Thursday's Recipe: " 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <TextView 
       android:id="@+id/thursdayRecipe" 
       android:layout_toRightOf="@+id/thursday" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
     </RelativeLayout> 
     <Spinner 
      android:id="@+id/thursdaySpinner" 
      android:layout_below="@+id/thursday" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"></Spinner> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/friday" 
       android:text="Friday's Recipe: " 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <TextView 
       android:id="@+id/fridayRecipe" 
       android:layout_toRightOf="@+id/friday" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
     </RelativeLayout> 
     <Spinner 
      android:id="@+id/fridaySpinner" 
      android:layout_below="@+id/friday" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"></Spinner> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/saturday" 
       android:text="Saturday's Recipe: " 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <TextView 
       android:id="@+id/saturdayRecipe" 
       android:layout_toRightOf="@+id/saturday" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
     </RelativeLayout> 
     <Spinner 
      android:id="@+id/saturdaySpinner" 
      android:layout_below="@+id/saturday" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"></Spinner> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/sunday" 
       android:text="Sunday's Recipe: " 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <TextView 
       android:id="@+id/sundayRecipe" 
       android:layout_toRightOf="@+id/sunday" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
     </RelativeLayout> 
     <Spinner 
      android:id="@+id/sundaySpinner" 
      android:layout_below="@+id/sunday" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"></Spinner> 

     <TextView 
      android:id="@+id/required" 
      android:layout_below="@+id/sundaySpinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

     <ListView 
      android:id="@+id/weeklyList" 
      android:layout_below="@+id/required" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="5" 
      ></ListView> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:gravity="center" 
      android:layout_height="wrap_content"> 

      <Button 
       android:id="@+id/cancelButton" 
       android:text="Cancel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 

      <Button 
       android:id="@+id/addButton" 
       android:text="Add" 
       android:layout_toRightOf="@id/cancelButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 

     </RelativeLayout> 


    </LinearLayout> 

    </ScrollView> 

    <FrameLayout 
     android:id="@+id/container_body" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

</android.support.design.widget.CoordinatorLayout> 


<fragment 
    android:id="@+id/fragment_navigation_drawer" 
    android:name="com.example.rory.pocketchef.Fragments.FragmentDrawer" 
    android:layout_width="@dimen/nav_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:layout="@layout/fragment_navigation_drawer" 
    tools:layout="@layout/fragment_navigation_drawer" /> 

</android.support.v4.widget.DrawerLayout> 
+0

顯示手機屏幕圖像,以便可以得到更好的主意。 –

回答

0

在滾動視圖使用android:fillViewport="true"。希望這能解決你的問題。

+0

感謝您的建議 – JJSmith

+0

感謝您接受答案。 –

+0

如果你不介意,我確實還有一個問題。所以當列表填充後,底部相對佈局中的兩個按鈕消失,你知道爲什麼會發生這種情況嗎?在將任何東西添加到列表之前,它們都在那裏 – JJSmith