Android开发滑动到顶部悬停效果

之前也出个微博悬停效果,但是它里面是底部是viewpager的,还有它的自定义控件过于复杂。

这次写一个底部就一个recyclerview,算是改良版本

废话先来看下效果图,是不是你们要的。由于我找不到csdn博客上上传视频的地方,只能上传效果。

第一张:首屏画面

第二张:滑动画面


三张:滑动留言精选处悬停效果

希望大家能看懂三张图,联想到其中的操作,第三张图的发表感想按钮是显示隐藏弄出来了的,它和留言精选同在一个父控件中的。

这个应该是处理事件分发应用的最好体现了,能自己搞出来的,事件分发就过关了。不过我也是在别人的基础上改的,嘿嘿。

核心代码:LetterStickyNavLayout

public class LetterStickyNavLayout extends LinearLayout  {
    private ScrollListener scrollListener;

    private Context mContext;

    private View mTop;
    private View mNav;

    //private ViewPager mViewPager;
    //private SwipeRefRecyclerView mSRRceylerView;
    private LinearLayout llContent;

    private int mTopViewHeight;
    private ViewGroup mInnerScrollView;
    private boolean isTopHidden = false;

    private OverScroller mScroller;
    private VelocityTracker mVelocityTracker;
    private int mTouchSlop;
    private int mMaximumVelocity, mMinimumVelocity;

    private float mLastY;
    private boolean mDragging;

    private boolean isInControl = false;
    private boolean isChange=false;
    private int screenWidth;

    public LetterStickyNavLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        setOrientation(LinearLayout.VERTICAL);
        mContext = context;

        mScroller = new OverScroller(context);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
        mMaximumVelocity = ViewConfiguration.get(context)
                .getScaledMaximumFlingVelocity();
        mMinimumVelocity = ViewConfiguration.get(context)
                .getScaledMinimumFlingVelocity();

        screenWidth=Utils.getScreenWidthPx(mContext);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mTop = findViewById(R.id.id_stickynavlayout_topview);
        mNav = findViewById(R.id.id_stickynavlayout_indicator);


        //View sfrView = findViewById(R.id.id_stickynavlayout_swiperefrecyclerview);
        View llView = findViewById(R.id.id_stickynavlayout_content);
        if (!(llView instanceof LinearLayout)) {
            throw new RuntimeException(
                    "id_stickynavlayout_content show used by LinearLayout !");
        }
//        if (!(sfrView instanceof SwipeRefRecyclerView)) {
//            throw new RuntimeException(
//                    "SwipeRefRecyclerView show used by SwipeRefRecyclerView !");
//        }
//
//        mSRRceylerView = (SwipeRefRecyclerView) sfrView;
        llContent =(LinearLayout)llView;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        ViewGroup.LayoutParams params;
//        if(mSRRceylerView != null && mSRRceylerView.getVisibility() == VISIBLE){
//            params = mSRRceylerView.getLayoutParams();
//        }else{
//            params = llContent.getLayoutParams();
//        }
        params = llContent.getLayoutParams();
        int height;
        if(Utils.checkDeviceHasNavigationBar(mContext)){
            height = getMeasuredHeight() - mNav.getMeasuredHeight() + Utils.dip2px(mContext, 34);
        }else{
            height = getMeasuredHeight() - mNav.getMeasuredHeight();
        }

        //int height = getMeasuredHeight() - mNav.getMeasuredHeight();
        if (height >= screenWidth && !isChange) {
            params.height = height;
            isChange = true;
        }

        


    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);

        mTopViewHeight = mTop.getMeasuredHeight()  ;
        LogUtils.i("mTopViewHeight",mTopViewHeight+"");

    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        int action = ev.getAction();
        float y = ev.getY();

        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mLastY = y;
                break;
            case MotionEvent.ACTION_MOVE:
                float dy = y - mLastY;

                getCurrentScrollView();

                if(mInnerScrollView != null && mInnerScrollView.getVisibility()== View.VISIBLE && mInnerScrollView instanceof SwipeRefRecyclerView){
                    LogUtils.i("swi","exist");
                    SwipeRefRecyclerView mSRRceylerView = (SwipeRefRecyclerView) mInnerScrollView;
                    Recyc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

893151960

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值