【问题标题】:The Whole DrawerLayout is scrollable整个 DrawerLayout 是可滚动的
【发布时间】:2017-01-06 12:35:40
【问题描述】:

我正在尝试阅读布局代码,但不知道为什么。 我有一个抽屉布局的代码,问题是整个抽屉布局是可滚动的,我只想让项目列表视图滚动而不是标题,我无法弄清楚,因为它看起来所有组件都是定制的。 有没有人可以看看。。 提前致谢

<?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:context="com.activities.MainActivity">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/ToolBarStyle"
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:background="?attr/colorPrimary">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="@dimen/abc_action_bar_default_height_material">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"

                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"
                    android:src="@drawable/menu_logo" />

            </RelativeLayout>
        </android.support.v7.widget.Toolbar>

        <ViewFlipper
            android:id="@+id/loading_switcher"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ProgressBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" />

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

                <android.support.design.widget.CoordinatorLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/checkout_container">

                    <android.support.design.widget.AppBarLayout
                        android:id="@+id/app_bar_layout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                        app:elevation="2dp">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@android:color/white"
                            android:orientation="vertical"
                            android:padding="10dp"
                            app:layout_scrollFlags="scroll|enterAlways">

                            <com.views.font.CustomFontTextView
                                android:id="@+id/location_text_view"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:drawableLeft="@drawable/ic_location_on_black_18dp"
                                android:ellipsize="end"
                                android:gravity="center_vertical"
                                android:maxLines="1"
                                android:singleLine="true"
                                android:text="Pick Location"
                                android:textColor="@color/colorPrimary"
                                android:textSize="15sp" />

                            <com.views.font.CustomFontTextView
                                android:id="@+id/locality_info_text_view"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:ellipsize="end"
                                android:gravity="center_vertical"
                                android:maxLines="1"
                                android:singleLine="true"
                                android:textColor="@android:color/black"
                                android:textSize="12sp" />
                        </LinearLayout>
                    </android.support.design.widget.AppBarLayout>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"                                          app:layout_behavior="@string/appbar_scrolling_view_behavior">

                        <android.support.v4.widget.SwipeRefreshLayout
                            android:id="@+id/product_list_swipe_layout"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginLeft="2dp"
                            android:layout_marginRight="2dp">

                            <android.support.v7.widget.RecyclerView
                                android:id="@+id/products_list_recycler_view"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent" />
                        </android.support.v4.widget.SwipeRefreshLayout>

                    </RelativeLayout>

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

                <com.views.CheckoutShelfView
                    android:id="@+id/checkout_container"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_alignParentBottom="true" />
            </RelativeLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:orientation="vertical">

                <com.views.font.CustomFontTextView
                    android:id="@+id/error_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    android:gravity="center"
                    android:textColor="@color/grey_bg"
                    android:textSize="20sp" />

                <com.views.font.CustomFontTextView
                    android:id="@+id/error_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/shape_green_fill_round_5dp"
                    android:drawablePadding="2dp"
                    android:gravity="center_vertical"
                    android:paddingBottom="5dp"
                    android:paddingLeft="4dp"
                    android:paddingRight="8dp"
                    android:paddingTop="5dp"
                    android:textAllCaps="false"
                    android:textColor="@android:color/white" />
            </LinearLayout>
        </ViewFlipper>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/header_navigation"
        app:itemIconTint="@color/colorPrimary"
        app:itemTextColor="@color/colorPrimary"
        app:menu="@menu/navigation_menu">

        <com.views.font.CustomFontTextView
            android:id="@+id/version_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|bottom"
            android:background="@android:color/white"
            android:gravity="center"
            android:padding="3dp"
            android:textSize="10sp">
            </com.views.font.CustomFontTextView>


    </android.support.design.widget.NavigationView>
    </ScrollView>
</android.support.v4.widget.DrawerLayout>

【问题讨论】:

    标签: android android-layout listview android-studio


    【解决方案1】:

    试试这个:

    从布局中删除Scrollview

    试试这个:

    <android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/header_navigation"
    app:itemIconTint="@color/colorPrimary"
    app:itemTextColor="@color/colorPrimary"
    app:menu="@menu/navigation_menu" />
    

    活动中;

    //mNavigationView is your navigation view
    mNavViewHeaderLayout = LayoutInflater.from(MainActivity.this).inflate(R.layout.header_navigation, mNavigationView);
    
    //to access content in header view
    mTextview = (TextView)mNavViewHeaderLayout.findViewById(R.id.textview);
    

    【讨论】:

    • 抽屉布局或导航布局是否有默认滚动视图??
    • 正如您在 xml 代码中看到的那样,标题被添加为导航布局中的另一个属性,所以我怎么能把它放出来,我不知道我可以将它包含在外部还是我应该做其他事情.请指导..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 2019-01-06
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多