我正在制作一个应用程序,我在该屏幕上有类别屏幕我在主屏幕上有8个按钮,但最后一个按钮隐藏在广告布局后面,所以现在我希望该用户应该能够使用滚动视图向上或向下滚动它为什么Scroll View无法在抽屉布局下工作。我不知道如何解决这个问题。
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>
在我的情况下,NestedScrollView工作而不是ScrollView。
也把android:focusableInTouchMode="true"
放在你的relativelayout但它不工作然后请发给我你的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">