Android仿網易新聞圖片詳情下滑隱藏效果示例代碼
更新時間:2018年07月05日 09:14:58 作者:楊澤楷
這篇文章主要給大家介紹了關于利用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的廣播Receiver動態(tài)注冊和靜態(tài)注冊示例
本篇文章主要介紹了Android的廣播Receiver動態(tài)注冊和靜態(tài)注冊示例,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02Android開發(fā)使用Messenger及Handler進行通信的方法示例
這篇文章主要介紹了Android開發(fā)使用Messenger及Handler進行通信的方法,結合實例形式分析了Android使用Messenger及Handler定義客戶端與服務器端實現通信的相關操作技巧,需要的朋友可以參考下2017-12-12