这篇文章主要为大家展示了“Android如何实现仿网易新闻图片详情下滑隐藏效果”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Android如何实现仿网易新闻图片详情下滑隐藏效果”这篇文章吧。
效果图:
实例代码
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);
}
}
以上是“Android如何实现仿网易新闻图片详情下滑隐藏效果”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。