为什么Scrollview在抽屉布局下不起作用

时间:2019-03-19 10:19:37

标签: android android-scrollview

我正在制作一个应用程序,该屏幕上有类别屏幕,主屏幕上有8个按钮,但最后一个按钮隐藏在广告版式后面,所以现在我希望该用户可以通过使用来上下滚动它滚动视图,但为什么滚动视图在抽屉布局下不起作用。我不知道如何解决这个问题。

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"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/startbg"
    android:fitsSystemWindows="true">

    <ScrollView
        android:id="@+id/SCROLLER_ID"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_centerVertical="true"
                android:gravity="center"
                android:orientation="vertical">

                <Button
                    android:id="@+id/btn1"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn1"
                    android:textColor="#fff" />

                <Button
                    android:id="@+id/btn2"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn2"
                    android:textColor="#fff" />

                <Button
                    android:id="@+id/btn2"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn3"
                    android:textColor="#fff" />

                <Button
                    android:id="@+id/btn4"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn4"
                    android:textColor="#fff" />

                <Button
                    android:id="@+id/btn5"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn5"
                    android:textColor="#fff" />

                <Button
                    android:id="@+id/btn6"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn6"
                    android:textColor="#fff" />

                <Button
                    android:id="@+id/btn7"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn7"
                    android:textColor="#fff" />


                <Button
                    android:id="@+id/btn8"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/custom_button"
                    android:padding="10dp"
                    android:text="btn8"
                    android:textColor="#fff" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true">

                <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/adView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    ads:adSize="BANNER"
                    ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
            </LinearLayout>
        </RelativeLayout>
    </ScrollView>

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

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

1 个答案:

答案 0 :(得分:0)

在我的情况下,NestedScrollView代替了ScrollView。

也将android:focusableInTouchMode="true"放在您的相对布局中,但是它不起作用,然后请也将您的java文件发送给我,以便我可以通过运行它进行检查。

以下是我的工作布局的摘要:请确保您没有将constrianlayout内的任何子视图高度都与父视图(0 dp)相匹配,也请确保滚动视图android:fillViewport="true";

如有疑问,请问我。

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

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/cvLayout"
            android:animateLayoutChanges="true">   



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

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/cvLayout"
        android:animateLayoutChanges="true">