2017-04-17 58 views
0

的底部我有一个由组成一个Android活动: 的FrameLayout>滚动型>的LinearLayout> ListView控件的Android LinearLayout中充入直到屏幕

我的ListView是我的最后一个组件,我想,它的高度规模将从去直到屏幕底部的前一个组件结束。 问题:不幸的是现在它的大小只有高度大小只有1行的大小。

我已将所有layout_height设置为match_parent属性,但没有任何效果。

问题:你会知道如何让我的ListView占据所有空间的高度下降到可用屏幕的底部?

谢谢!

XML

<FrameLayout 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" 
    tools:context="it.bitrack.fabio.bitrack.ScheduleView" 
    android:layout_marginTop="60dp"> 

    <!-- TODO: Update blank fragment layout --> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/textView7" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:text="Select an asset" 
       android:textStyle="bold|italic" /> 

      <Spinner 
       android:id="@+id/assetSpinner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:textStyle="bold|italic" /> 

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

       <TextView 
        android:id="@+id/textView9" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        android:text="Booking schedule" 
        android:textStyle="bold|italic" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="horizontal"> 

        <TextView 
         android:id="@+id/textView12" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:padding="10dp" 
         android:text="From: " 
         android:textStyle="bold|italic" /> 

        <TextView 
         android:id="@+id/fromDatetimeTextView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:text="Date and time" /> 

        <ImageButton 
         android:id="@+id/setFromDatetimeImageButton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:src="@android:drawable/ic_menu_my_calendar" /> 

        <TextView 
         android:id="@+id/textView13" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="10dp" 
         android:text="To: " 
         android:textStyle="bold|italic" /> 

        <TextView 
         android:id="@+id/toDatetimeTextView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:text="Date and time" /> 

        <ImageButton 
         android:id="@+id/setToDatetimeImageButton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:src="@android:drawable/ic_menu_my_calendar" /> 
       </LinearLayout> 

       <Button 
        android:id="@+id/assetBookingButton" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Proceed with booking" /> 

      </LinearLayout> 


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

       <TextView 
        android:id="@+id/textView8" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        android:text="Current bookings" 
        android:textStyle="bold|italic" /> 

       <ListView 
        android:id="@+id/assetBookingsListView" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 
      </LinearLayout> 

     </LinearLayout>> 
    </ScrollView> 

</FrameLayout> 

回答

0

使用此布局代码:

<RelativeLayout 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:layout_marginTop="60dp"> 

    <!-- TODO: Update blank fragment layout --> 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/textView7" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:text="Select an asset" 
       android:textStyle="bold|italic" /> 

      <Spinner 
       android:id="@+id/assetSpinner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:textStyle="bold|italic" /> 

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

       <TextView 
        android:id="@+id/textView9" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        android:text="Booking schedule" 
        android:textStyle="bold|italic" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="horizontal"> 

        <TextView 
         android:id="@+id/textView12" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:padding="10dp" 
         android:text="From: " 
         android:textStyle="bold|italic" /> 

        <TextView 
         android:id="@+id/fromDatetimeTextView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:text="Date and time" /> 

        <ImageButton 
         android:id="@+id/setFromDatetimeImageButton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:src="@android:drawable/ic_menu_my_calendar" /> 

        <TextView 
         android:id="@+id/textView13" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="10dp" 
         android:text="To: " 
         android:textStyle="bold|italic" /> 

        <TextView 
         android:id="@+id/toDatetimeTextView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:text="Date and time" /> 

        <ImageButton 
         android:id="@+id/setToDatetimeImageButton" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="5dp" 
         android:src="@android:drawable/ic_menu_my_calendar" /> 
       </LinearLayout> 

       <Button 
        android:id="@+id/assetBookingButton" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Proceed with booking" /> 

      </LinearLayout> 

     </LinearLayout> 
    </ScrollView> 

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

     <TextView 
      android:id="@+id/textView8" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="10dp" 
      android:text="Current bookings" 
      android:textStyle="bold|italic" /> 

     <ListView 
      android:id="@+id/assetBookingsListView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 

</RelativeLayout> 

夫妇的建议:

  1. 不要的使用listviewScrollView ...
  2. 使用RelativeLayout作为根元素,以在另一个 之后对齐视图。
  3. 对于scrollView使用android:layout_height="wrap_content"android:fillViewport="true"

输出:

enter image description here