Android仿網(wǎng)易新聞圖片詳情下滑隱藏效果示例代碼
前言
本文主要給大家分享了Android仿網(wǎng)易新聞圖片詳情下滑隱藏效果的相關(guān)內(nèi)容,分享出來供需要的朋友參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧
效果圖:

實例代碼
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);
}
}
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
Android實現(xiàn)ListView左右滑動刪除和編輯
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)ListView左右滑動刪除和編輯的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-05-05
Android 實現(xiàn)監(jiān)聽的四種方法詳解實例代碼
這篇文章主要介紹了Android 實現(xiàn)監(jiān)聽的方法詳解實例代碼的相關(guān)資料,這里整理了四種方法,需要的朋友可以參考下2016-10-10
Android監(jiān)聽滑動控件實現(xiàn)狀態(tài)欄顏色切換
這篇文章給大家分享一個平時在滑動頁面經(jīng)常遇到的效果:滑動過程動態(tài)修改狀態(tài)欄顏色,文中有詳細(xì)的示例代碼,對我們的學(xué)習(xí)或工作有一定的幫助,感興趣的小伙伴自己動手試試吧2023-08-08
Android UI控件RatingBar實現(xiàn)自定義星星評分效果
這篇文章主要為大家詳細(xì)介紹了Android UI控件RatingBar實現(xiàn)自定義星星評分效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02

