android+新闻+图片,Android仿网易新闻图片详情可下滑隐藏

efc2846e51ff4f3fa1d3d4f9.html

imageide

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);

}

}

16人点赞this

做者:沐_Andorid开发者

连接:https://www.jianshu.com/p/edc68bf5f9f5

来源:简书

著做权归做者全部。商业转载请联系做者得到受权,非商业转载请注明出处。code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值