浮动框停留在底部

在上一篇中,已经介绍了悬浮框停留在 顶部 , 如还没有看过的,请可以先看看 仿大众、美团悬浮框顶部悬停,因为本文是在其基础上稍加,修改而来:

首先修改一下 布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/parent_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:paddingLeft="20dp"
        android:textColor="#fcfbfb"
        android:background="#00998c"
        android:text="浮动在顶部"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <come.huitong.fei.testapplication.MyScrollView
            android:id="@+id/scrollView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/iamge"
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    android:background="#996699"
                    android:scaleType="centerCrop"/>

                <ImageView
                    android:id="@+id/buy"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@mipmap/buy" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    android:background="#006699"
                    android:scaleType="centerCrop"/>

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="360dp"
                    android:background="#00990f"
                    android:scaleType="centerCrop"/>

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="400dp"
                    android:background="#99008c"
                    android:scaleType="centerCrop"/>
            </LinearLayout>


        </come.huitong.fei.testapplication.MyScrollView>


        <ImageView
            android:id="@+id/top_buy_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@mipmap/buy"
            android:visibility="gone"/>

    </FrameLayout>

</LinearLayout>

然后,在主Activity中 修改一下onScroll 方法 :

/**
     * 注意:  mBuyLayout 的 父控件,是 MyScrollView (因为 getTop() 获取的 是 到 父控件的 顶端的 距离)
     * @param scrollY
     */
    @Override
    public void onScroll(int scrollY) {
        Log.i("距离", "scrollY==" + scrollY + "   mBuyLayout.getTop()" + mBuyLayout.getTop()+
        "  mBuyLayout.getTop() "+ mBuyLayout.getTop());

        if(scrollY < mBuyLayout.getTop()){

            mTopBuyLayout.setVisibility(View.GONE);

        }else{

            mTopBuyLayout.setVisibility(View.VISIBLE);
        }

    }

至此,就完成了 页面向上滑动时,底部出现停留的 效果 。 本篇都是在 上一篇 (都很简单)的基础上完成的。
同时,像这种 浮动框 在上面 或是 在下面 ,原理都一样,这样实现起来,也简单方便,好理解。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值