【问题标题】:Disable scrolling of a button in a scrollable layout in android在android的可滚动布局中禁用按钮的滚动
【发布时间】:2020-08-31 10:28:41
【问题描述】:

我有一个带有 FrameLayout 的协调器布局。 我为此框架布局设置了 app:layout_behavior="@string/appbar_scrolling_view_behavior"。

但我想在这个片段中有一个固定的按钮,我不希望这个按钮有滚动。 我该怎么做??

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:background="@color/colorPrimary"
android:fitsSystemWindows="true"
tools:openDrawer="end">


<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
    <!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:elevation="0dp">

        <!-- Toolbar is the actual app bar with text and the action items -->
        <include
            android:id="@+id/action_bar"
            layout="@layout/custom_action_bar" />
    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/but_nav_bar"
        android:layout_marginTop="-25dp"
        android:layout_marginBottom="@dimen/_30sdp"
        android:paddingBottom="@dimen/_30sdp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
   
</androidx.coordinatorlayout.widget.CoordinatorLayout>

<include layout="@layout/bottom_navigation_layout" />

<include layout="@layout/navigation_bar" />


</androidx.drawerlayout.widget.DrawerLayout>

这是 myFragment 的代码

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

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/shopsList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" />
     <Button
         android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        text="button"/>
 </RelativeLayout>

【问题讨论】:

    标签: android scroll appbar


    【解决方案1】:

    您还没有提到要修复按钮的位置。 添加android:layout_alignParentBottom="true" 会将按钮固定在屏幕底部。

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:text="button" />
    

    【讨论】:

    • 我设置了 android:layout_alignParentBottom="true" 但是当滚动回收视图时,按钮滚动了一点...我不明白为什么会发生这种情况以及如何解决它。
    猜你喜欢
    • 2016-08-01
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    相关资源
    最近更新 更多