我正在開發一個具有導航抽屜的滾動視圖佈局的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>
其中你關閉了scrollview標籤? –
您在該佈局中沒有抽屜。也就是說,你沒有一個'View',它是'DrawerLayout'的直接子節點,並且具有適當的'layout_gravity'屬性。 –
我在linearlayout之後關閉了滾動視圖@Zeeshan – user3778886