当前位置:   article > 正文

Android--仿QQ空间动态页(继续拖动查看详情)及标题栏渐变_android 仿qq空间动态成品

android 仿qq空间动态成品

最近一直比较忙,也没抽出时间来写博客,人一懒就说明都不想做了。
博客如果不能坚持的话,那就没什么意义了,也就废了,最近研究了一下QQ空间动态页面,自己也试着写了一个,现在拿出来分享给大家,好了,废话不多说,切入正题,先看看我们今天要实现功能的效果图:

来看下我们今天要介绍的主角
PullToZoomInListView
github地址如下:https://github.com/matrixxun/PullToZoomInListView
一个下拉放大的空间,这种效果在ios应用中很常见,Android中不少应用也有它的身影,玩过QQ的人都知道,QQ空间动态界面有着这几个功能(下拉刷新,图片放大,上拉加载更多,标题栏渐变,图标变化)
我本着不重复造轮子,在前人的基础上而外添加了些功能
1、添加了一个footer
2、添加了一个监听器,用于监听下拉刷新和上拉加载更多
3、添加了一个判断是否有更多数据的方法

修改后的PullToZoomInListView代码如下:

public class PullToZoomListView extends ListView implements AbsListView.OnScrollListener {

    private View footerView;
    private TextView tv_footer_text;
    private View fl_progress_bar;
    private boolean isNoMore = false;
    private boolean isLoad = false;
    private static final Interpolator sInterpolator = new Interpolator() {
        public float getInterpolation(float paramAnonymousFloat) {
            float f = paramAnonymousFloat - 1.0F;
            return 1.0F + f * (f * (f * (f * f)));
        }
    };
    int mActivePointerId = -1;
    private FrameLayout mHeaderContainer;
    private int mHeaderHeight;

    public int getmHeaderHeight() {
        return mHeaderHeight;
    }

    /**
     * 设置头部的高度
     *
     * @param mHeaderHeight
     */
    public void setmHeaderHeight(int mHeaderHeight) {
        this.mHeaderHeight = mHeaderHeight;
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(DensityUtil.dp2px(mContext,
                AbsListView.LayoutParams.MATCH_PARENT), mHeaderHeight);
        getHeaderContainer().setLayoutParams(lp);
    }

    private ImageView mHeaderImage;
    float mLastMotionY = -1.0F;
    float mLastScale = -1.0F;
    float mMaxScale = -1.0F;
    private AbsListView.OnScrollListener mOnScrollListener;
    private ScalingRunnalable mScalingRunnalable;
    private int mScreenHeight;
    private ImageView mShadow;

    private Context mContext;

    public PullToZoomListView(Context paramContext) {
        super(paramContext);
        init(paramContext);
        mContext = paramContext;
    }

    public PullToZoomListView(Context paramContext, AttributeSet paramAttributeSet) {
        super(paramContext, paramAttributeSet);
        init(paramContext);
        mContext = paramContext;
    }

    public PullToZoomListView(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
        super(paramContext, paramAttributeSet, paramInt);
        init(paramContext);
        mContext = paramContext;
    }

    private void endScraling() {
        if (this.mHeaderContainer.getBottom() >= this.mHeaderHeight)
            Log.d("mmm", "endScraling");
        this.mScalingRunnalable.startAnimation(100L);
    }

    private void init(Context paramContext) {
        DisplayMetrics localDisplayMetrics = new DisplayMetrics();
        ((Activity) paramContext).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
        this.mScreenHeight = localDisplayMetrics.heightPixels;
        this.mHeaderContainer = new FrameLayout(paramContext);

        this.mHeaderImage = new ImageView(paramContext);
        mHeaderImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
        int i = localDisplayMetrics.widthPixels;
        setHeaderViewSize(i, (int) (9.0F * (i / 16.0F)));
        this.mShadow = new ImageView(paramContext);
        FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(-1, -2);
        localLayoutParams.gravity = Gravity.CENTER;
        this.mShadow.setLayoutParams(localLayoutParams);
        this.mHeaderContainer.addView(this.mHeaderImage);
        this.mHeaderContainer.addView(this.mShadow);
        // addHeaderView(this.mHeaderContainer);
        footerView = LayoutInflater.from(paramContext).inflate(R.layout.zoomlistview_footer, null);
        tv_footer_text = (TextView) footerView.findViewById(R.id.tv_footer_text);
        fl_progress_bar = footerView.findViewById(R.id.fl_progress_bar);
        //addFooterView
        addFooterView(footerView);
        this.mScalingRunnalable = new ScalingRunnalable();
        super.setOnScrollListener(this);
    }

    private void onSecondaryPointerUp(MotionEvent paramMotionEvent) {
        int i = (paramMotionEvent.getAction()) >> 8;
        if (paramMotionEvent.getPointerId(i) == this.mActivePointerId)
            if (i != 0) {
                this.mLastMotionY = paramMotionEvent.getY(0);
                this.mActivePointerId = paramMotionEvent.getPointerId(0);
                return;
            }
    }

    private void reset() {
        this.mActivePointerId = -1;
        this.mLastMotionY = -1.0F;
        this.mMaxScale = -1.0F;
        this.mLastScale = -1.0F;
    }

    public ImageView getHeaderView() {
        return this.mHeaderImage;
    }

    public FrameLayout getHeaderContainer() {
        return mHeaderContainer;
    }

    public void setHeaderView() {
        addHeaderView(this.mHeaderContainer);
    }

    /*
     * public boolean onInterceptTouchEvent(MotionEvent ev) {
     *
     * final int action = ev.getAction() & MotionEvent.ACTION_MASK; float
     * mInitialMotionX= 0; float mLastMotionX= 0;
     *
     * float mInitialMotionY= 0; float mLastMotionY = 0;
     *
     * boolean isIntercept=false; switch (action) { case
     * MotionEvent.ACTION_DOWN:
     *
     * mLastMotionY=ev.getY(); break;
     *
     * case MotionEvent.ACTION_MOVE: mInitialMotionY = ev.getY();
     *
     * if(Math.abs(mInitialMotionY-mLastMotionY)>50) { isIntercept=true; }
     * break;
     *
     * }
     *
     * return isIntercept; }
     */

    protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/292908
推荐阅读
相关标签
  

闽ICP备14008679号