2016-08-16 47 views
-1

我正在開發一個具有導航抽屜的滾動視圖佈局的Android應用程序。但導航抽屜沒有展開或者沒有使用scrollview。但是當我使用LinearLyout而不是ScrollView時,導航抽屜工作正常。Android導航抽屜不支持滾動視圖

這是我的xml文件:

這是activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<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" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

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

這是app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout  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:fitsSystemWindows="true" 
tools:context="com.example.hotel.hotelreservation.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

<include layout="@layout/content_main" /> 

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

這是content_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

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

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="10dp" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 


    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:src="@drawable/hotellogo" 
     android:layout_marginTop="50dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Arrival Date" 
     android:id="@+id/textView2" 
     android:textColor="#c0392b" 
     android:layout_marginTop="50dp"/> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="date" 
     android:ems="10" 
     android:id="@+id/editText" 
     android:drawableLeft="@drawable/date_icon" 
     android:hint=" yyyy-mm-dd" 
     android:padding="20dp" 
     android:textColor="#ffffff" 
     style="@style/Base.V12.Widget.AppCompat.EditText" 
     android:backgroundTint="#c0392b"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Departure Date" 
     android:id="@+id/textView3" 
     android:textColor="#c0392b" 
     android:layout_marginTop="30dp"/> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="date" 
     android:ems="10" 
     android:id="@+id/editText1" 
     android:drawableLeft="@drawable/date_icon" 
     android:hint=" yyyy-mm-dd" 
     android:padding="20dp" 
     android:textColor="#ffffff" 
     style="@style/Base.V12.Widget.AppCompat.EditText" 
     android:backgroundTint="#c0392b"/> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="SEARCH" 
     android:background="#c0392b" 
     android:textColor="#ffffff" 
     android:layout_marginTop="30dp" 
     android:id="@+id/btnSearch" 
     android:onClick="submit"/> 

</LinearLayout> 
</ScrollView> 
</android.support.v4.widget.DrawerLayout> 

這是nav_he ader_mail.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="@dimen/nav_header_height" 
android:background="@drawable/side_nav_bar" 
android:gravity="bottom" 
android:orientation="vertical" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/nav_header_vertical_spacing" 
    android:src="@android:drawable/sym_def_app_icon" /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/nav_header_vertical_spacing" 
    android:text="Hotel Booking" 
    android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="An online hotel booking system" /> 

</LinearLayout> 
+0

其中你關閉了scrollview標籤? –

+0

您在該佈局中沒有抽屜。也就是說,你沒有一個'View',它是'DrawerLayout'的直接子節點,並且具有適當的'layout_gravity'屬性。 –

+0

我在linearlayout之後關閉了滾動視圖@Zeeshan – user3778886

回答

1
<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:orientation="vertical"> 


    <ScrollView android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="10dp" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 


     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/hotellogo" 
      android:layout_marginTop="50dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Arrival Date" 
      android:id="@+id/textView2" 
      android:textColor="#c0392b" 
      android:layout_marginTop="50dp"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:ems="10" 
      android:id="@+id/editText" 
      android:drawableLeft="@drawable/date_icon" 
      android:hint=" yyyy-mm-dd" 
      android:padding="20dp" 
      android:textColor="#ffffff" 
      style="@style/Base.V12.Widget.AppCompat.EditText" 
      android:backgroundTint="#c0392b"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Departure Date" 
      android:id="@+id/textView3" 
      android:textColor="#c0392b" 
      android:layout_marginTop="30dp"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:ems="10" 
      android:id="@+id/editText1" 
      android:drawableLeft="@drawable/date_icon" 
      android:hint=" yyyy-mm-dd" 
      android:padding="20dp" 
      android:textColor="#ffffff" 
      style="@style/Base.V12.Widget.AppCompat.EditText" 
      android:backgroundTint="#c0392b"/> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="SEARCH" 
      android:background="#c0392b" 
      android:textColor="#ffffff" 
      android:layout_marginTop="30dp" 
      android:id="@+id/btnSearch" 
      android:onClick="submit"/> 

    </LinearLayout> 
    </ScrollView> 
    </LinearLayout> 
    <!-- The navigation drawer ListView--> 
     <ListView android:id="@+id/left_drawer_home" 
      android:layout_width="240dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:divider="@null" 
      android:dividerHeight="0dp" 
      android:background="#ffffff"/> 


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

試試這個。它可能會幫助你 –

+0

不工作@瑞詩凱詩pathak – user3778886

+0

它會工作,因爲它在我的case.just複製並粘貼上面的XML並嘗試它。@ user3778886.I附加屏幕截圖見 –

0

你的代碼更改爲:

content_main.xml

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

<LinearLayout 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="10dp" 
xmlns:android="http://schemas.android.com/apk/res/android"> 


<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="150dp" 
    android:src="@drawable/hotellogo" 
    android:layout_marginTop="50dp"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Arrival Date" 
    android:id="@+id/textView2" 
    android:textColor="#c0392b" 
    android:layout_marginTop="50dp"/> 

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="date" 
    android:ems="10" 
    android:id="@+id/editText" 
    android:drawableLeft="@drawable/date_icon" 
    android:hint=" yyyy-mm-dd" 
    android:padding="20dp" 
    android:textColor="#ffffff" 
    style="@style/Base.V12.Widget.AppCompat.EditText" 
    android:backgroundTint="#c0392b"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Departure Date" 
    android:id="@+id/textView3" 
    android:textColor="#c0392b" 
    android:layout_marginTop="30dp"/> 

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="date" 
    android:ems="10" 
    android:id="@+id/editText1" 
    android:drawableLeft="@drawable/date_icon" 
    android:hint=" yyyy-mm-dd" 
    android:padding="20dp" 
    android:textColor="#ffffff" 
    style="@style/Base.V12.Widget.AppCompat.EditText" 
    android:backgroundTint="#c0392b"/> 

<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="SEARCH" 
    android:background="#c0392b" 
    android:textColor="#ffffff" 
    android:layout_marginTop="30dp" 
    android:id="@+id/btnSearch" 
    android:onClick="submit"/> 

我已刪除了DrawerLayout從這個文件,因爲它是這裏不需要,請試試這個代碼,讓我知道你是否有任何問題。

0

我用你的佈局,並修改它和它的工作檢查我重視我的截圖

enter image description here

下面是代碼

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:orientation="vertical"> 


    <ScrollView android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="10dp" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 


     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/hotellogo" 
      android:layout_marginTop="50dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Arrival Date" 
      android:id="@+id/textView2" 
      android:textColor="#c0392b" 
      android:layout_marginTop="50dp"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:ems="10" 
      android:id="@+id/editText" 
      android:drawableLeft="@drawable/date_icon" 
      android:hint=" yyyy-mm-dd" 
      android:padding="20dp" 
      android:textColor="#ffffff" 
      style="@style/Base.V12.Widget.AppCompat.EditText" 
      android:backgroundTint="#c0392b"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Departure Date" 
      android:id="@+id/textView3" 
      android:textColor="#c0392b" 
      android:layout_marginTop="30dp"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:ems="10" 
      android:id="@+id/editText1" 
      android:drawableLeft="@drawable/date_icon" 
      android:hint=" yyyy-mm-dd" 
      android:padding="20dp" 
      android:textColor="#ffffff" 
      style="@style/Base.V12.Widget.AppCompat.EditText" 
      android:backgroundTint="#c0392b"/> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="SEARCH" 
      android:background="#c0392b" 
      android:textColor="#ffffff" 
      android:layout_marginTop="30dp" 
      android:id="@+id/btnSearch" 
      android:onClick="submit"/> 

    </LinearLayout> 
    </ScrollView> 
    </LinearLayout> 
    <!-- The navigation drawer ListView--> 
     <ListView android:id="@+id/left_drawer_home" 
      android:layout_width="240dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:divider="@null" 
      android:dividerHeight="0dp" 
      android:background="#ffffff"/> 


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

我已經發布代碼也看到以上 –

0

使用NestedScrollView而不是滾動型

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/nScrollView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <FrameLayout ...> 
     <ListView ... /> 
    </FrameLayout > 
</android.support.v4.widget.NestedScrollView> 
+0

請接受,如果你覺得它有用 – Don