Android 仿网易新闻图片详情中的详情描述

/**
 * 作者:Yann.Yang on 16/8/18 16:01
 * 邮箱:Yann.Yang@movite-tech.com
 * 说明:仿网易新闻图片详情中的详情描述,可上拉显示所有
 */
public class InfoTextView extends AutoRelativeLayout {

    private Context context;
    private int lastY;
    private int offY;

    private int MIN_HEIGHT = 600;

    public InfoTextView(Context context) {
        super(context);

        this.context = context;

        init();
    }

    public InfoTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

        this.context = context;

        init();
    }

    public InfoTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        this.context = context;

        init();
    }


    private void init() {
        View root = inflate(context, R.layout.ad_detail_text_layout, this);

    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return true;
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        boolean isConsume = false;
        int y = (int) ev.getY();
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                isConsume = true;
                lastY = y;

                break;
            case MotionEvent.ACTION_MOVE:
                offY = y - lastY;

                int[] screenSize = ScreenUtils.getScreenSize(context, false);

                if (getTop() >= (screenSize[1] - MIN_HEIGHT)) {
                    break;
                }

//                Log.d("yzk", "y " + y + " getTop " + getTop()
//                        + " getBottom " + getBottom()
//                        + " screenSize[1] - getMeasuredHeight " + (screenSize[1] - getMeasuredHeight())
//                        + " screenSize[1] - MIN_HEIGHT " + (screenSize[1] - MIN_HEIGHT));

                if ((offY > 0 && getTop() < screenSize[1] - MIN_HEIGHT)
                        || offY < 0 && getTop() > screenSize[1] - getMeasuredHeight()) {
                    layout(getLeft(), getTop() + offY,
                            getRight(), getBottom() + offY);
                }

                break;
            case MotionEvent.ACTION_UP:
                break;
        }

        return isConsume || super.dispatchTouchEvent(ev);
    }
}

    原文作者:杨同学
    原文地址: https://zhuanlan.zhihu.com/p/22074163
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞