Example usage for android.view View getScrollY

List of usage examples for android.view View getScrollY

Introduction

In this page you can find the example usage for android.view View getScrollY.

Prototype

public final int getScrollY() 

Source Link

Document

Return the scrolled top position of this view.

Usage

From source file:Main.java

static void offsetDescendantMatrix(ViewParent target, View view, Matrix m) {
    final ViewParent parent = view.getParent();
    if (parent instanceof View && parent != target) {
        final View vp = (View) parent;
        offsetDescendantMatrix(target, vp, m);
        m.preTranslate(-vp.getScrollX(), -vp.getScrollY());
    }// ww  w .  j  a v  a2 s .c o m

    m.preTranslate(view.getLeft(), view.getTop());

    if (!view.getMatrix().isIdentity()) {
        m.preConcat(view.getMatrix());
    }
}

From source file:com.zzc.androidtrain.view.refresh.Utils.java

public static boolean isScrollToTop(View target) {
    if (target instanceof NestedScrollView) {
        return target.getScrollY() == 0;
    } else if (target instanceof RecyclerView) {
        return ((RecyclerView) target).getLayoutManager()
                .findViewByPosition(ObservableRecyclerView.HEADER_VIEW_POSITION) != null
                && ((RecyclerView) target).computeVerticalScrollOffset() == 0;
    }//  ww  w. ja v  a  2  s .co m
    return true;
}

From source file:Main.java

/**
 * Inverse of {@link #getDescendantCoordRelativeToSelf(View, int[])}.
 *///from   w  ww  . ja v  a2  s .c o  m
public static float mapCoordInSelfToDescendent(View descendant, View root, int[] coord) {
    ArrayList<View> ancestorChain = new ArrayList<View>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    Matrix inverse = new Matrix();
    int count = ancestorChain.size();
    for (int i = count - 1; i >= 0; i--) {
        View ancestor = ancestorChain.get(i);
        View next = i > 0 ? ancestorChain.get(i - 1) : null;

        pt[0] += ancestor.getScrollX();
        pt[1] += ancestor.getScrollY();

        if (next != null) {
            pt[0] -= next.getLeft();
            pt[1] -= next.getTop();
            next.getMatrix().invert(inverse);
            inverse.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }

    coord[0] = (int) Math.round(pt[0]);
    coord[1] = (int) Math.round(pt[1]);
    return scale;
}

From source file:Main.java

public static Bitmap getBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
    canvas.translate(-view.getScrollX(), -view.getScrollY());
    view.draw(canvas);/*from w w  w  .  j  av  a2 s  .  c  om*/
    return bitmap;
}

From source file:Main.java

static Bitmap convertViewToBitmap(View view) {
    view.clearFocus();//w  w  w. ja  v  a  2 s. co m
    Bitmap bitmap = createBitmapSafely(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_4444, 2);
    if (bitmap != null) {
        mCanvas.setBitmap(bitmap);
        mCanvas.translate(-view.getScrollX(), -view.getScrollY());
        view.draw(mCanvas);
        mCanvas.setBitmap(null);
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap getBitmapFromView(View v) {
    if (v == null) {
        return null;
    }/*from   w w w  .ja  v a 2s  .c o  m*/
    Bitmap screenShot;
    screenShot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas mCanvas = new Canvas(screenShot);
    mCanvas.translate(-v.getScrollX(), -v.getScrollY());
    v.draw(mCanvas);
    return screenShot;
}

From source file:cn.bingoogolapple.refreshlayout.util.BGARefreshScrollingUtil.java

public static boolean isScrollViewOrWebViewToTop(View view) {
    return view != null && view.getScrollY() == 0;
}

From source file:Main.java

/**
 * Maps a coorindate in a descendant view into the parent.
 *//*  w w w.  j ava  2  s  .co m*/
public static float mapCoordInDescendentToSelf(View descendant, View root, float[] coord,
        boolean includeRootScroll) {
    ArrayList<View> ancestorChain = new ArrayList<View>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root && v != null) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    for (int i = 0; i < count; i++) {
        View v0 = ancestorChain.get(i);
        // For TextViews, scroll has a meaning which relates to the text position
        // which is very strange... ignore the scroll.
        if (v0 != descendant || includeRootScroll) {
            pt[0] -= v0.getScrollX();
            pt[1] -= v0.getScrollY();
        }

        v0.getMatrix().mapPoints(pt);
        pt[0] += v0.getLeft();
        pt[1] += v0.getTop();
        scale *= v0.getScaleX();
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}

From source file:com.lanma.customviewproject.utils.ScrollingUtil.java

/**
 * view???/*from  ww w . ja  v  a 2 s  .co m*/
 */
public static boolean isScrollViewOrWebViewToTop(View view) {
    return view != null && view.getScrollY() == 0;
}

From source file:Main.java

/**
 * Maps a coordinate in a descendant view into the parent.
 *//*from  w ww.  j a  v  a 2  s  .  c o  m*/
public static float mapCoordInDescendentToSelf(View descendant, View root, float[] coord,
        boolean includeRootScroll) {
    ArrayList<View> ancestorChain = new ArrayList<>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root && v != null) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    for (int i = 0; i < count; i++) {
        View v0 = ancestorChain.get(i);
        // For TextViews, scroll has a meaning which relates to the text position
        // which is very strange... ignore the scroll.
        if (v0 != descendant || includeRootScroll) {
            pt[0] -= v0.getScrollX();
            pt[1] -= v0.getScrollY();
        }

        v0.getMatrix().mapPoints(pt);
        pt[0] += v0.getLeft();
        pt[1] += v0.getTop();
        scale *= v0.getScaleX();
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}