android – 如何在RecyclerView的滚动上向上向下滚动底部栏

android – 如何在RecyclerView的滚动上向上向下滚动底部栏,第1张

概述随着Google最近发布的设计支持库,推出了许多酷炫的新视图.使用一些新的组件(例如CoordinatorLayout)可能(!)使您能够实现滚动行为. 我尝试了一些内置的滚动行为,但没有什么是为我工作, 我的布局中有一个底线(LinearLayout)代替FloatingActionButton 在这里我想要什么 >这个屏幕底部的OnLaunch应该出现. >在回收站底部的滚动条上应该向下滚动. 随着Google最近发布的设计支持库,推出了许多酷炫的新视图.使用一些新的组件(例如CoordinatorLayout)可能(!)使您能够实现滚动行为.

我尝试了一些内置的滚动行为,但没有什么是为我工作,

我的布局中有一个底线(linearLayout)代替floatingActionbutton

在这里我想要什么

>这个屏幕底部的OnLaunch应该出现.
>在回收站底部的滚动条上应该向下滚动.
>在滚动浏览底部栏的向下滚动应该会d出

有没有内在机制来实现呢?或者我们需要编写java代码?

这是我的代码:

main_activty.xml

<androID.support.design.Widget.CoordinatorLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:fitsSystemwindows="true">    <androID.support.design.Widget.AppbarLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:fitsSystemwindows="true"        androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar">        <include layout="@layout/toolbar_srp" />        <androID.support.design.Widget.TabLayout            androID:ID="@+ID/tabs"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:elevation="5dp"            app:tabGravity="fill"            app:tabIndicatorcolor="@androID:color/white"            app:tabMode="fixed" />    </androID.support.design.Widget.AppbarLayout>    <!-- All Scrollable VIEws -->    <androID.support.v4.vIEw.VIEwPager        androID:ID="@+ID/vIEwpager"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        app:layout_behavior="@string/appbar_scrolling_vIEw_behavior" />    <!-- Bottom bar-->    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_gravity="bottom"        androID:background="#a0000000"        androID:orIEntation="horizontal"        androID:paddingBottom="@dimen/padding_small"        androID:paddingtop="@dimen/padding_small">        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.33"            androID:gravity="center"            androID:paddingBottom="@dimen/padding_small"            androID:paddingtop="@dimen/padding_small"            androID:text="AC"            androID:textcolor="@color/white" />        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.33"            androID:gravity="center"            androID:paddingBottom="@dimen/padding_small"            androID:paddingtop="@dimen/padding_small"            androID:text="Sleeper"            androID:textcolor="@color/white" />        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.33"            androID:gravity="center"            androID:paddingBottom="@dimen/padding_small"            androID:paddingtop="@dimen/padding_small"            androID:text="Premium"            androID:textcolor="@color/white" />    </linearLayout></androID.support.design.Widget.CoordinatorLayout>

fragment.xml(这里我把我的回收器视图代码)

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@color/white"    androID:orIEntation="vertical">    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:paddingBottom="@dimen/padding_small"        androID:paddingtop="@dimen/padding_small"        androID:weightSum="1">        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.33"            androID:background="@drawable/bg_srp_sorter"            androID:clickable="true"            androID:gravity="center"            androID:paddingBottom="@dimen/padding_small"            androID:paddingtop="@dimen/padding_small"            androID:text="Departure" />        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.33"            androID:background="@drawable/bg_srp_sorter"            androID:gravity="center"            androID:paddingBottom="@dimen/padding_small"            androID:paddingtop="@dimen/padding_small"            androID:text="Duration" />        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.33"            androID:gravity="center"            androID:paddingBottom="@dimen/padding_small"            androID:paddingtop="@dimen/padding_small"            androID:text="Price" />    </linearLayout>    <VIEw        androID:layout_wIDth="match_parent"        androID:layout_height="1dp"        androID:background="@color/lite_gray"></VIEw>    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:orIEntation="vertical"        androID:weightSum="1">        <androID.support.v7.Widget.RecyclerVIEw            androID:ID="@+ID/bus_List_recycler_vIEw"            androID:layout_wIDth="match_parent"            androID:layout_height="0dp"            androID:layout_weight="1" />    </linearLayout></linearLayout>

toolbar.xml

<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.Toolbar xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    androID:ID="@+ID/toolbar"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:background="@color/colorPrimary"    app:layout_scrollFlags="scroll|enteralways"    androID:minHeight="?attr/actionbarSize">    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:weightSum="1">        <linearLayout            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.10">            <ImageVIEw                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:src="@drawable/abc_ic_ab_back_mtrl_am_Alpha" />        </linearLayout>        <linearLayout            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.78"            androID:orIEntation="vertical">            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal"                androID:weightSum="1">                <TextVIEw                    androID:ID="@+ID/toolbar_Title_source"                    androID:layout_wIDth="0dp"                    androID:layout_height="wrap_content"                    androID:layout_weight="0.47"                    androID:ellipsize="end"                    androID:singleline="true"                    androID:text="Thiruvananthapuram "                    androID:textcolor="@color/white"                    androID:textSize="@dimen/label_text_size_large" />                <TextVIEw                    androID:ID="@+ID/toolbar_Title_arrow"                    androID:layout_wIDth="0dp"                    androID:layout_height="wrap_content"                    androID:layout_weight="0.08"                    androID:text="@string/char_right"                    androID:textcolor="@color/white"                    androID:textSize="@dimen/label_text_size_large"                    androID:textStyle="bold" />                <TextVIEw                    androID:ID="@+ID/toolbar_Title_destination"                    androID:layout_wIDth="0dp"                    androID:layout_height="wrap_content"                    androID:layout_weight="0.47"                    androID:ellipsize="end"                    androID:singleline="true"                    androID:text=" Cochin"                    androID:textcolor="@color/white"                    androID:textSize="@dimen/label_text_size_large" />            </linearLayout>            <TextVIEw                androID:ID="@+ID/toolbar_sub_Title"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:text="2 Seat(s)"                androID:textcolor="@color/lite_gray"                androID:textSize="@dimen/label_text_size_normal" />        </linearLayout>        <linearLayout            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="0.13">            <ImageVIEw                androID:layout_wIDth="30dp"                androID:layout_height="30dp"                androID:scaleType="fitCenter"                androID:src="@drawable/filter" />        </linearLayout>    </linearLayout></androID.support.v7.Widget.Toolbar>
解决方法 由于您正在使用CoordinatorLayout,您可以创建一个可以实现您所请求的自定义行为,如下所示:
创建一个扩展CoordinatorLayout.Behavior< VIEw>以下示例:
public class QuickReturnfloaterBehavior extends CoordinatorLayout.Behavior<VIEw> {    private int distance;    public QuickReturnfloaterBehavior(Context context,AttributeSet attrs) {        super(context,attrs);    }    @OverrIDe    public boolean onStartnestedScroll(CoordinatorLayout coordinatorLayout,VIEw child,VIEw directTargetChild,VIEw target,int nestedScrollAxes) {        return (nestedScrollAxes & VIEwCompat.SCRolL_AXIS_VERTICAL) != 0;    }    @OverrIDe public voID onnestedPreScroll(CoordinatorLayout coordinatorLayout,int dx,int dy,int[] consumed) {        if (dy > 0 && distance < 0 || dy < 0 && distance > 0) {            child.animate().cancel();            distance = 0;        }        distance += dy;        final int height = child.getHeight() > 0 ? (child.getHeight()) : 600/*update this accordingly*/;        if (distance > height && child.isShown()) {            hIDe(child);        } else if (distance < 0 && !child.isShown()) {            show(child);        }    }    private voID hIDe(VIEw vIEw) {        vIEw.setVisibility(VIEw.GONE);// use animate.translateY(height); instead    }    private voID show(VIEw vIEw) {        vIEw.setVisibility(VIEw.VISIBLE);// use animate.translateY(-height); instead    }}

现在应用此行为将其添加到您的布局

app:layout_behavior="com.example.QuickReturnfloaterBehavior"
总结

以上是内存溢出为你收集整理的android – 如何在RecyclerView的滚动上向上/向下滚动底部栏全部内容,希望文章能够帮你解决android – 如何在RecyclerView的滚动上向上/向下滚动底部栏所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1132865.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存