這篇文章主要介紹“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怎么實現仿網易新聞圖片詳情下滑隱藏效果”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。