Example usage for android.widget ScrollView getChildAt

List of usage examples for android.widget ScrollView getChildAt

Introduction

In this page you can find the example usage for android.widget ScrollView getChildAt.

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:Main.java

public static void setScrollViewHeightBasedOnChild(ScrollView scrollView) {
    View child = scrollView.getChildAt(0);
    ViewGroup.LayoutParams params = (LayoutParams) scrollView.getLayoutParams();
    params.height = child.getHeight();/*w w  w . j  av  a2 s . c  o  m*/
    scrollView.setLayoutParams(params);
}

From source file:Main.java

public static Bitmap createBitmap(Context context, ScrollView v) {
    int width = 0, height = 0;
    for (int i = 0; i < v.getChildCount(); i++) {
        width += v.getChildAt(i).getWidth();
        height += v.getChildAt(i).getHeight();
    }//from   w ww.ja v a 2  s  .c o m
    if (width <= 0 || height <= 0) {
        return null;
    }
    int h = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
    if (height < h)
        height = h;
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);
    return bitmap;
}

From source file:com.my.seams_carv.util.ScrollableViewUtil.java

/**
 * Return true if the given scrollable view is over scrolling in terms of
 * the given y momentum.//from  ww  w.j  a v a 2s . co  m
 * <br/>
 * Usually it is called in the {@code dispatchTouchEvent}, {@code onTouchEvent},
 * or the {@code onInterceptTouchEvent}.
 *
 * @param view the scrollable view.
 * @param dy The y momentum.
 * @return true if the view is over scrolling in the vertical direction.
 */
public static boolean ifOverScrollingVertically(View view, float dy) {
    if (view == null || dy == 0)
        return false;

    // TODO: Test it.
    if (view instanceof ScrollView) {
        final ScrollView scrollView = (ScrollView) view;
        final View child = scrollView.getChildAt(0);
        if (scrollView.getHeight() >= child.getHeight())
            return true;

        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return scrollView.getScrollY() == 0;
        } else {
            // Slide the thumb up to scroll down the list.
            MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams();

            return child.getHeight() - scrollView.getScrollY() == scrollView.getHeight()
                    - (params.topMargin + params.bottomMargin);
        }
        //        } else if (view instanceof WebView) {
        //            WebView webView = (WebView) view;
        //
        //            // TODO: Complete it.
        //            if (dy > 0) {
        //                // Slide the thumb down to scroll up the list.
        //                return webView.computeHorizontalScrollOffset() == 0.f;
        //            } else {
        //                // Slide the thumb up to scroll down the list.
        //                return false;
        //            }
    } else if (view instanceof NestedScrollView) {
        final NestedScrollView scrollView = (NestedScrollView) view;
        final int scrollRange = scrollView.computeVerticalScrollRange()
                - scrollView.computeVerticalScrollExtent();

        if (scrollRange <= 0)
            return true;

        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return scrollView.computeVerticalScrollOffset() == 0.f;
        } else {
            // Slide the thumb up to scroll down the list.
            return scrollView.computeVerticalScrollOffset() == scrollRange;
        }
    } else if (view instanceof ListView) {
        final ListView listView = (ListView) view;
        if (listView.getAdapter().getCount() == 0)
            return true;

        // TODO: Complete it.
        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return listView.getScrollY() == 0;
        } else {
            // Slide the thumb up to scroll down the list.
            return false;
        }
    } else if (view instanceof RecyclerView) {
        final RecyclerView recyclerView = (RecyclerView) view;
        if (recyclerView.getAdapter().getItemCount() == 0)
            return true;

        final int scrollRange = recyclerView.computeVerticalScrollRange()
                - recyclerView.computeVerticalScrollExtent();

        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return recyclerView.computeVerticalScrollOffset() == 0.f;
        } else {
            // Slide the thumb up to scroll down the list.
            return recyclerView.computeVerticalScrollOffset() == scrollRange;
        }
    }
    // TODO: Support more scrollable view.

    // Return true for the unsupported view because the dy is non-zero.
    return true;
}

From source file:com.duy.pascal.ui.editor.view.LineUtils.java

public static int getYAtLine(ScrollView scrollView, int lineCount, int line) {
    if (lineCount == 0)
        return 0;
    return scrollView.getChildAt(0).getHeight() / lineCount * line;
}

From source file:com.bobomee.android.common.util.ScreenUtil.java

/**
 * http://blog.csdn.net/lyy1104/article/details/40048329
 *//*from   w  ww .j  a v a  2 s. co  m*/
public static Bitmap shotScrollView(ScrollView scrollView) {
    int h = 0;
    Bitmap bitmap = null;
    for (int i = 0; i < scrollView.getChildCount(); i++) {
        h += scrollView.getChildAt(i).getHeight();
        scrollView.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff"));
    }
    bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.RGB_565);
    final Canvas canvas = new Canvas(bitmap);
    scrollView.draw(canvas);
    return bitmap;
}

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

public static boolean isScrollViewToBottom(ScrollView scrollView) {
    if (scrollView != null) {
        int scrollContentHeight = scrollView.getScrollY() + scrollView.getMeasuredHeight()
                - scrollView.getPaddingTop() - scrollView.getPaddingBottom();
        int realContentHeight = scrollView.getChildAt(0).getMeasuredHeight();
        if (scrollContentHeight == realContentHeight) {
            return true;
        }/*from ww  w .  j a v a2 s  . co m*/
    }
    return false;
}

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

/**
 * ScrollView?//from   ww w .  ja v a 2  s .c o  m
 */
public static boolean isScrollViewToBottom(ScrollView scrollView) {
    if (scrollView != null) {
        int scrollContentHeight = scrollView.getScrollY() + scrollView.getMeasuredHeight()
                - scrollView.getPaddingTop() - scrollView.getPaddingBottom();
        int realContentHeight = scrollView.getChildAt(0).getMeasuredHeight();
        if (scrollContentHeight == realContentHeight) {
            return true;
        }
    }
    return false;
}

From source file:com.miku.framelite.widget.SwipeRefreshLayout.java

/**
 * @return Whether it is possible for the child view of this layout to
 *         scroll up. Override this if the child view is a custom view.
 *//* w w w  . j av  a  2s  .c om*/
public boolean canChildScrollDown() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getCount() - 1
                            || absListView.getChildAt(absListView.getChildCount() - 1)
                                    .getBottom() > absListView.getHeight() - absListView.getPaddingBottom());
        } else if (mTarget instanceof ScrollView) {
            final ScrollView scrollView = (ScrollView) mTarget;
            return scrollView.getChildAt(0).getMeasuredHeight() > scrollView.getHeight()
                    + scrollView.getScrollY();
        } else {
            throw new IllegalStateException(
                    "SwipeRefreshLayout swipe down can host child (AbsListView and scrollView)");
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
}

From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java

public View getMainScrollViewContentFromRoot(View root) {
    if (root != null) {
        ScrollView mainScrollViewFromRoot = getMainScrollViewFromRoot(root);
        if (mainScrollViewFromRoot != null) {
            return mainScrollViewFromRoot.getChildAt(0);
        }/* w ww  .ja va2 s.c o m*/
    }
    return null;
}

From source file:com.google.reviewit.ReviewChangesFragment.java

private void init() {
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) v(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setColorSchemeColors(widgetUtil.color(R.color.progressBar));
    swipeRefreshLayout.setRefreshing(true);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override//from w  ww. j  ava 2 s . c om
        public void onRefresh() {
            getApp().getQueryHandler().reset();
            loadAndDisplay(true);
        }
    });

    v(R.id.reloadButton).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            reloadQuery();
        }
    });

    final View nextPageProgress = v(R.id.nextPageProgress);
    final ScrollView scrollView = (ScrollView) v(R.id.scrollView);
    scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            if (isAdded() && getApp().getQueryHandler().hasNext()
                    && nextPageProgress.getVisibility() == View.GONE) {
                View lastChild = scrollView.getChildAt(scrollView.getChildCount() - 1);
                if ((lastChild.getBottom() - (scrollView.getHeight() + scrollView.getScrollY())) == 0) {
                    setVisible(nextPageProgress);
                    scrollView.post(new Runnable() {
                        @Override
                        public void run() {
                            scrollView.fullScroll(View.FOCUS_DOWN);
                            loadAndDisplay();
                        }
                    });
                }
            }
        }
    });
}