工具栏将与所有内容一起滚动。否则不起作用

问题描述 投票:0回答:1

工具栏将与所有内容一起滚动。

我试图将工具栏代码放在ScrollView之前,但是我完全看不到工具栏。我尝试使用LinearLayout更改DrawerLayout的位置,但之后甚至无法运行应用程序。

工具栏将与所有内容一起滚动。

我试图将工具栏代码放在ScrollView之前,但是我完全看不到工具栏。我尝试使用LinearLayout更改DrawerLayout的位置,但之后甚至无法运行应用程序。

工具栏将与所有内容一起滚动。

我试图将工具栏代码放在ScrollView之前,但是我完全看不到工具栏。我尝试使用LinearLayout更改DrawerLayout的位置,但之后甚至无法运行应用程序。

有什么建议吗?

<?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">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

        <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="wrap_content"
            android:background="@color/white"
            android:orientation="vertical"
            android:weightSum="100"
            tools:context="cz.johngalt.app.MainActivity">

            <include
                layout="@layout/app_bar_main"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="10" />


            <include
                layout="@layout/content_main"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="10dp"
                android:layout_weight="18"
                android:src="@drawable/logo" />


            <android.support.v7.widget.GridLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="72"
                android:background="@color/white"
                android:paddingBottom="14dp"
                android:paddingEnd="14dp"
                android:paddingStart="14dp"
                app:alignmentMode="alignMargins"
                app:columnCount="2"
                app:columnOrderPreserved="false"
                app:rowCount="3">

                <!-- Row 1 -->
                <!-- Column 1 -->
                <android.support.v7.widget.CardView
                    android:id="@+id/cv_rooms"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="6dp"
                    android:background="@color/white"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="8dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|center_vertical"
                        android:layout_margin="16dp"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:src="@drawable/ic_airline_seat_flat_black_24dp" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/d_menu_rooms"
                            android:textAlignment="center"
                            android:textColor="@android:color/black"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        >
                    </LinearLayout>

                </android.support.v7.widget.CardView>

                <!-- Column 2 -->
                <android.support.v7.widget.CardView
                    android:id="@+id/cv_apps"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="6dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="8dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|center_vertical"
                        android:layout_margin="16dp"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:src="@drawable/ic_menu_slideshow" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/d_applications"
                            android:textAlignment="center"
                            android:textColor="@android:color/black"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        >
                    </LinearLayout>

                </android.support.v7.widget.CardView>


                <!-- Row 2 -->
                <!-- Column 1 -->
                <android.support.v7.widget.CardView
                    android:id="@+id/cv_taxi"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_marginBottom="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="6dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="8dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|center_vertical"
                        android:layout_margin="16dp"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:src="@drawable/taxi_icon" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/d_menu_taxi"
                            android:textAlignment="center"
                            android:textColor="@android:color/black"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        >
                    </LinearLayout>

                </android.support.v7.widget.CardView>
                <!--Column 2-->


                <!-- Row 3 -->
                <!-- Column 1 -->
                <android.support.v7.widget.CardView
                    android:id="@+id/cv_gallery"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="6dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="8dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|center_vertical"
                        android:layout_margin="16dp"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:src="@drawable/ic_image_black_24dp" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/photo_gallery"
                            android:textAlignment="center"
                            android:textColor="@android:color/black"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        >
                    </LinearLayout>

                </android.support.v7.widget.CardView>

                <android.support.v7.widget.CardView
                    android:id="@+id/cv_contact"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="6dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="8dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|center_vertical"
                        android:layout_margin="16dp"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:src="@drawable/contact_info_main" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/d_menu_contact"
                            android:textAlignment="center"
                            android:textColor="@android:color/black"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        >
                    </LinearLayout>

                </android.support.v7.widget.CardView>
                <!--Column 2-->
                <android.support.v7.widget.CardView
                    android:id="@+id/cv_location"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="6dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="8dp"
                    app:layout_columnWeight="1"
                    app:layout_rowWeight="1">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|center_vertical"
                        android:layout_margin="16dp"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:src="@drawable/ic_location_on_black_24dp" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/d_menu_location"
                            android:textAlignment="center"
                            android:textColor="@android:color/black"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                        >
                    </LinearLayout>

                </android.support.v7.widget.CardView>

            </android.support.v7.widget.GridLayout>

        </LinearLayout>
    </ScrollView>

    <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.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>
android xml layout toolbar
1个回答
0
投票

您的工具栏将继续滚动,只要它嵌套在ScrollView中即可。

您可能想使LinearLayout成为DrawerLayout的直接子代,然后将工具栏放置在LinearLayout内,与Scrollview处于相同的层次结构级别。这是一个例子:

<?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">

      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/white"
          android:orientation="vertical"
          android:weightSum="100"
          tools:context="cz.johngalt.app.MainActivity">

        <!-- here's the toolbar -->
        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="10" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white">
                
                <!-- here goes the rest of your xml -->
        
        <ScrollView/>            

      <LinearLayout/>

    <android.support.v4.widget.DrawerLayout/>
© www.soinside.com 2019 - 2024. All rights reserved.