欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

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

时间:2021-03-27 09:29:07|栏目: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 Dialog对话框的五种形式

栏    目:Android代码

下一篇:Android根据不同身份配置APP对应的不同模块方法

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

本文地址:http://www.codeinn.net/misctech/88783.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有