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

實(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);
}
}
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
- Android實(shí)現(xiàn)雅虎新聞?wù)虞d視差動畫效果
- Android開發(fā)實(shí)現(xiàn)自定義新聞加載頁面功能實(shí)例
- Android UI設(shè)計(jì)與開發(fā)之PopupWindow仿騰訊新聞底部彈出菜單
- Android RecyclerView仿新聞頭條的頻道管理功能
- Android網(wǎng)絡(luò)編程之簡易新聞客戶端
- Android模擬實(shí)現(xiàn)網(wǎng)易新聞客戶端
- Android 模擬新聞APP顯示界面滑動優(yōu)化實(shí)例代碼
- Android實(shí)現(xiàn)基本功能的新聞應(yīng)用
相關(guān)文章
Android的廣播Receiver動態(tài)注冊和靜態(tài)注冊示例
本篇文章主要介紹了Android的廣播Receiver動態(tài)注冊和靜態(tài)注冊示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02
Kotlin中的Checked Exception機(jī)制淺析
這篇文章主要給大家介紹了關(guān)于Kotlin中Checked Exception機(jī)制的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Android開發(fā)使用Messenger及Handler進(jìn)行通信的方法示例
這篇文章主要介紹了Android開發(fā)使用Messenger及Handler進(jìn)行通信的方法,結(jié)合實(shí)例形式分析了Android使用Messenger及Handler定義客戶端與服務(wù)器端實(shí)現(xiàn)通信的相關(guān)操作技巧,需要的朋友可以參考下2017-12-12
Flutter學(xué)習(xí)LogUtil封裝與實(shí)現(xiàn)實(shí)例詳解
這篇文章主要為大家介紹了Flutter學(xué)習(xí)LogUtil封裝與實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09

