十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章主要介紹“Android怎么實(shí)現(xiàn)仿網(wǎng)易新聞圖片詳情下滑隱藏效果”的相關(guān)知識,小編通過實(shí)際案例向大家展示操作過程,操作方法簡單快捷,實(shí)用性強(qiáng),希望這篇“Android怎么實(shí)現(xiàn)仿網(wǎng)易新聞圖片詳情下滑隱藏效果”文章能幫助大家解決問題。
效果圖:
實(shí)例代碼
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); } }
關(guān)于“Android怎么實(shí)現(xiàn)仿網(wǎng)易新聞圖片詳情下滑隱藏效果”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識點(diǎn)。