zoukankan      html  css  js  c++  java
  • android 根据滑动隐藏或显示导航 类似手机QQ好友个人信息

    //重写ScrollView
    
    
    public class NotifyingScrollView extends ScrollView {
         /**
         * @author Cyril Mottier
         */
        public interface OnScrollChangedListener {
            void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt);
        }
    
        private OnScrollChangedListener mOnScrollChangedListener;
    
        public NotifyingScrollView(Context context) {
            super(context);
        }
    
        public NotifyingScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public NotifyingScrollView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
            super.onScrollChanged(l, t, oldl, oldt);
            if (mOnScrollChangedListener != null) {
                mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);
            }
        }
    
        public void setOnScrollChangedListener(OnScrollChangedListener listener) {
            mOnScrollChangedListener = listener;
        }
    
    }
    View Code

    布局引用重写NotifyingScrollView控件

     <你的项目路径.NotifyingScrollView
                android:id="@id/sv_personal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/layout_bg"
                android:scrollbars="none" >
        
     <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/layout_bg"
                    android:orientation="vertical" >
    你要显示的内容
    </LinearLayout>
            </你的项目路径.NotifyingScrollView>
    View Code

    activity使用引用

    NotifyingScrollView sv_personal=(NotifyingScrollView)findViewById(R.id.sv_personal);
    sv_personal.setOnScrollChangedListener(mOnScrollChangedListener);
    
    
    
    private NotifyingScrollView.OnScrollChangedListener mOnScrollChangedListener = new NotifyingScrollView.OnScrollChangedListener() {
    public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
    int Height=Utility.dip2px(context, 130);
    float ratio =Math.max(Math.min(1, t/Height), 0);
    //导航控件
    linar_top.setAlpha(ratio* 255);
    }
    };
    View Code

     int Height=Utility.dip2px(context, 130); 130为要滑动的高度

  • 相关阅读:
    dynamic debug动态打印
    leetcode:Pascal's Triangle II (杨辉三角形,空间限制)【面试算法题】
    HDU 1671 Phone List 二叉树水题 数组建树法
    栈和队列
    一张图理解O(1)算法
    uva 10608
    C# 写的工作任务 Job 定时调度框架 WebWork (Quartz.NET) Web版的Windows服务
    PHP伪造referer突破防盗链
    php 文件上传一例简单代码
    PHP 图片文件上传代码
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/4209752.html
Copyright © 2011-2022 走看看