栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android仿网易新闻图片详情下滑隐藏效果示例代码

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对考高分网的支持。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/155929.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号