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監(jiān)聽滑動控件實現狀態(tài)欄顏色切換
這篇文章給大家分享一個平時在滑動頁面經常遇到的效果:滑動過程動態(tài)修改狀態(tài)欄顏色,文中有詳細的示例代碼,對我們的學習或工作有一定的幫助,感興趣的小伙伴自己動手試試吧2023-08-08
Android UI控件RatingBar實現自定義星星評分效果
這篇文章主要為大家詳細介紹了Android UI控件RatingBar實現自定義星星評分效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02

