简体   繁体   English

DrawerLayout内部的ConstraintLayout引起一些问题

[英]ConstraintLayout inside DrawerLayout causes some problems

I am working on an app that uses a DrawerLayout. 我正在使用DrawerLayout的应用程序上工作。 The fragment containing this layout also contains some scrollable content. 包含此布局的片段还包含一些可滚动的内容。

So the main layout of this fragment is a DrawerLayout , below is the include block for the app bar , then the ScrollView block, which contains a ConstraintLayout so that I can put all the content I need in the ScrollView . 因此,此片段的主要布局是DrawerLayout ,下面是app bar的include块,然后是ScrollView块,其中包含ConstraintLayout以便我可以将所需的所有内容放入ScrollView Here is the code in details : 这是详细的代码:

<?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
        android:id="@+id/appBarMain"
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

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

        <android.support.constraint.ConstraintLayout
            android:id="@+id/lytDashboardContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="76dp">

            <Button
                android:id="@+id/btnAwaitingReview"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_marginEnd="30dp"
                android:layout_marginStart="30dp"
                android:background="@drawable/rounded_corners_color_primary"
                android:text="42 avis en attente"
                android:textAllCaps="false"
                android:textColor="@color/grey"
                android:textSize="16sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager
                android:id="@+id/rvpPlaceOfTheDay"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:paddingBottom="10dp"
                android:paddingEnd="20dp"
                android:paddingStart="20dp"
                android:paddingTop="10dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/btnAwaitingReview"
                app:rvp_singlePageFling="true"
                app:rvp_triggerOffset="0.1" />

            <TextView
                android:id="@+id/lblDateNews"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="30dp"
                android:layout_marginStart="30dp"
                android:layout_marginTop="30dp"
                android:text="Dimanche 31 Fevrier"
                android:textColor="@color/colorPrimaryDark"
                android:textSize="16sp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/rvpPlaceOfTheDay" />

            <View
                android:id="@+id/separator"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginEnd="30dp"
                android:layout_marginStart="30dp"
                android:layout_marginTop="10dp"
                android:background="@color/grey"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/lblDateNews" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rvNews"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="20dp"
                android:layout_marginStart="20dp"
                android:layout_marginTop="10dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/separator" />

        </android.support.constraint.ConstraintLayout>

    </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/fragment_dashboard_drawer" />

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

But there are two problems : 但是有两个问题:

  • The first is that the NavigationDrawer button at the top left is no more clickable. 首先是左上角的NavigationDrawer按钮不再可单击。 I know that this is caused by the ConstraintLayout because I tried putting every element as a comment one by one, and it worked properly as long as I uncommented the ConstraintLayout , but I couldn't find a way to solve it. 我知道这是由ConstraintLayout引起的,因为我尝试将每个元素作为注释一一放置,并且只要我对ConstraintLayout不加注释,它就可以正常工作,但是我找不到解决方法。
  • And the second is that the ScrollView scrolls over the app bar as you can see on this screenshot. 第二个是ScrollView滚动到app bar如您在此屏幕截图中所见。 For this one I couldn't figure out the source of the problem... 对于这个我无法弄清楚问题的根源...

ScrollView在应用栏上滚动

I'm not 100% sure but my guess is: 我不确定100%,但是我的猜测是:

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

It that won't help try wrapping ScrollView with eg. 它不会帮助尝试将ScrollView与例如包装在一起。 LinearLayout. LinearLayout。

Hope it helps. 希望能帮助到你。

感谢迈克M.我解决我的问题,所以我的错误是把我的ScrollView后我包括app_bar_main ,从而结束了覆盖它,因此该解决方案是简单地移动ScrollViewapp_bar_main ,后AppBarLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM