最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義scrollView實(shí)現(xiàn)頂部圖片下拉放大

 更新時(shí)間:2017年12月22日 16:01:54   作者:liujinhua1992  
這篇文章主要為大家詳細(xì)介紹了Android自定義scrollView實(shí)現(xiàn)頂部圖片下拉放大,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了scrollView實(shí)現(xiàn)頂部圖片下拉放大的具體代碼,供大家參考,具體內(nèi)容如下

之前的scrollView頂部圖片下拉放大在之后的項(xiàng)目用到了幾次,但沒(méi)次都寫(xiě)在Activity中很麻煩,也不方便復(fù)用。這幾天有空,所以重新使用自定義scrollView的方法實(shí)現(xiàn)這個(gè)效果。原理和之前的基本是一致的,所以也不多說(shuō)了,直接上代碼。

package com.example.myapplication.dropzoom; 
 
import android.animation.ObjectAnimator; 
import android.animation.ValueAnimator; 
import android.content.Context; 
import android.util.AttributeSet; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ScrollView; 
 
/** 
 * Created by Liujinhua on 2016/3/25. 
 * 下拉放大scrollView 
 */ 
public class DropZoomScrollView extends ScrollView implements View.OnTouchListener { 
 
  // 記錄首次按下位置 
  private float mFirstPosition = 0; 
  // 是否正在放大 
  private Boolean mScaling = false; 
 
  private View dropZoomView; 
  private int dropZoomViewWidth; 
  private int dropZoomViewHeight; 
 
  public DropZoomScrollView(Context context) { 
    super(context); 
  } 
 
  public DropZoomScrollView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
  } 
 
  public DropZoomScrollView(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
  } 
 
  @Override 
  protected void onFinishInflate() { 
    super.onFinishInflate(); 
    init(); 
  } 
 
  @Override 
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
 
  } 
 
  private void init() { 
    setOverScrollMode(OVER_SCROLL_NEVER); 
    if (getChildAt(0) != null) { 
      ViewGroup vg = (ViewGroup) getChildAt(0); 
      if (vg.getChildAt(0) != null) { 
        dropZoomView = vg.getChildAt(0); 
        setOnTouchListener(this); 
 
      } 
    } 
  } 
 
  @Override 
  public boolean onTouch(View v, MotionEvent event) { 
    if (dropZoomViewWidth <= 0 || dropZoomViewHeight <= 0) { 
      dropZoomViewWidth = dropZoomView.getMeasuredWidth(); 
      dropZoomViewHeight = dropZoomView.getMeasuredHeight(); 
    } 
    switch (event.getAction()) { 
      case MotionEvent.ACTION_UP: 
        //手指離開(kāi)后恢復(fù)圖片 
        mScaling = false; 
        replyImage(); 
        break; 
      case MotionEvent.ACTION_MOVE: 
        if (!mScaling) { 
          if (getScrollY() == 0) { 
            mFirstPosition = event.getY();// 滾動(dòng)到頂部時(shí)記錄位置,否則正常返回 
          } else { 
            break; 
          } 
        } 
        int distance = (int) ((event.getY() - mFirstPosition) * 0.6); // 滾動(dòng)距離乘以一個(gè)系數(shù) 
        if (distance < 0) { // 當(dāng)前位置比記錄位置要小,正常返回 
          break; 
        } 
 
        // 處理放大 
        mScaling = true; 
        setZoom(1 + distance); 
        return true; // 返回true表示已經(jīng)完成觸摸事件,不再處理 
    } 
    return false; 
  } 
 
  // 回彈動(dòng)畫(huà) (使用了屬性動(dòng)畫(huà)) 
  public void replyImage() { 
    final float distance = dropZoomView.getMeasuredWidth() - dropZoomViewWidth; 
 
    // 設(shè)置動(dòng)畫(huà) 
    ValueAnimator anim = ObjectAnimator.ofFloat(0.0F, 1.0F).setDuration((long) (distance * 0.7)); 
 
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
      @Override 
      public void onAnimationUpdate(ValueAnimator animation) { 
        float cVal = (Float) animation.getAnimatedValue(); 
        setZoom(distance - ((distance) * cVal)); 
      } 
    }); 
    anim.start(); 
 
  } 
 
  //縮放 
  public void setZoom(float s) { 
    if (dropZoomViewHeight <= 0 || dropZoomViewWidth <= 0) { 
      return; 
    } 
    ViewGroup.LayoutParams lp = dropZoomView.getLayoutParams(); 
    lp.width = (int) (dropZoomViewWidth + s); 
    lp.height = (int) (dropZoomViewHeight * ((dropZoomViewWidth + s) / dropZoomViewWidth)); 
    dropZoomView.setLayoutParams(lp); 
  } 
} 

使用的時(shí)候也十分的簡(jiǎn)單

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical"> 
 
  <com.example.myapplication.dropzoom.DropZoomScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
 
 
      <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/bg" /> 
 
      <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/home_bg" /> 
 
      <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/home_bg" /> 
 
      <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/home_bg" /> 
 
      <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/home_bg" /> 
    </LinearLayout> 
  </com.example.myapplication.dropzoom.DropZoomScrollView> 
</LinearLayout> 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android 進(jìn)度條組件ProgressBar

    android 進(jìn)度條組件ProgressBar

    本文主要介紹android 進(jìn)度條組件ProgressBar,這里整理進(jìn)度條的實(shí)現(xiàn)代碼和效果圖,幫助大家學(xué)習(xí)理解Android 進(jìn)度條的知識(shí),有興趣的小伙伴可以參考下
    2016-09-09
  • 基于Android RecyclerView實(shí)現(xiàn)宮格拖拽效果

    基于Android RecyclerView實(shí)現(xiàn)宮格拖拽效果

    在Android發(fā)展的進(jìn)程中,網(wǎng)格布局一直比較有熱度,其中一個(gè)原因是對(duì)用戶來(lái)說(shuō)便捷操作,對(duì)app廠商而言也會(huì)帶來(lái)很多的曝光量,本篇我們會(huì)使用RecyclerView來(lái)實(shí)現(xiàn)網(wǎng)格拖拽,本篇將結(jié)合圖片分片案例,實(shí)現(xiàn)拖拽效果,需要的朋友可以參考下
    2024-03-03
  • Android RecyclerView上拉加載和下拉刷新

    Android RecyclerView上拉加載和下拉刷新

    這篇文章主要為大家詳細(xì)介紹了Android RecycleView上拉加載和下拉刷新的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android編程實(shí)現(xiàn)實(shí)時(shí)監(jiān)聽(tīng)EditText文本輸入的方法

    Android編程實(shí)現(xiàn)實(shí)時(shí)監(jiān)聽(tīng)EditText文本輸入的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)實(shí)時(shí)監(jiān)聽(tīng)EditText文本輸入的方法,結(jié)合實(shí)例形式分析了EditText控件及事件響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下
    2017-06-06
  • Android Button 自帶陰影效果另一種解決辦法

    Android Button 自帶陰影效果另一種解決辦法

    這篇文章主要介紹了Android Button 自帶陰影效果另一種解決辦法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-03-03
  • 深入理解Android MD5數(shù)據(jù)加密

    深入理解Android MD5數(shù)據(jù)加密

    在Android中需要對(duì)各種數(shù)據(jù)進(jìn)行加密的操作,比如用戶短信備份的數(shù)據(jù)加密、用戶賬戶登陸的密碼加密以及應(yīng)用于服務(wù)器連接傳遞重要數(shù)據(jù)的加密,用處非常的多,所以今天來(lái)總結(jié)一下MD5加密算法。
    2016-09-09
  • Android 廣播大全 Intent Action 事件詳解

    Android 廣播大全 Intent Action 事件詳解

    這篇文章主要給大家介紹Android 廣播大全 Intent Action 事件詳解,涉及到android廣播action 方面知識(shí)點(diǎn),本文講解的非常的全面,感興趣的朋友一起看看吧
    2015-10-10
  • Android實(shí)現(xiàn)多線程下載文件的方法

    Android實(shí)現(xiàn)多線程下載文件的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)多線程下載文件的方法,以實(shí)例形式較為詳細(xì)的分析了Android多線程文件傳輸及合并等操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • android實(shí)現(xiàn)掃描網(wǎng)頁(yè)二維碼進(jìn)行網(wǎng)頁(yè)登錄功能

    android實(shí)現(xiàn)掃描網(wǎng)頁(yè)二維碼進(jìn)行網(wǎng)頁(yè)登錄功能

    這篇文章主要介紹了android掃描網(wǎng)頁(yè)二維碼進(jìn)行網(wǎng)頁(yè)登錄效果,掃描成功之后跳轉(zhuǎn)進(jìn)入主頁(yè),具體實(shí)現(xiàn)代碼大家參考下本文
    2017-12-12
  • Android banner的使用詳解與示例

    Android banner的使用詳解與示例

    小編給大家分享一下android如何實(shí)現(xiàn)banner輪播圖無(wú)限輪播效果,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧
    2021-11-11

最新評(píng)論

海林市| 马尔康县| 湖州市| 苍南县| 任丘市| 淮阳县| 长汀县| 安丘市| 长汀县| 柘城县| 晋中市| 高陵县| 松江区| 聂拉木县| 南部县| 云南省| 黄浦区| 清原| 安阳县| 临城县| 万年县| 神农架林区| 陕西省| 达孜县| 乌兰县| 富锦市| 南木林县| 江油市| 聂拉木县| 彭州市| 双桥区| 商城县| 江城| 哈密市| 翁牛特旗| 安远县| 安新县| 肥乡县| 剑川县| 潢川县| 黔江区|