我正在制作一个应用程序,在这个屏幕上我有类别屏幕,主屏幕上有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>
发布于 2019-03-19 11:00:01
在我的例子中,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">
https://stackoverflow.com/questions/55238580
复制相似问题