Java Code Examples for android.widget.ScrollView#getHeight()

The following examples show how to use android.widget.ScrollView#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewPosition.java    From show-case-card-view with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Point getScrollPosition(@Nullable ScrollView scrollView) {

    if (scrollView == null || scrollView.findViewById(view.getId()) == null) {
        // scrollview not set, or child is not part of the scrollview content: do not scroll.
        return null;
    }

    // get the top of the item relative to the ScrollView:
    Rect offsetViewBounds = new Rect();
    view.getDrawingRect(offsetViewBounds);
    scrollView.offsetDescendantRectToMyCoords(view, offsetViewBounds);
    int relativeTop = offsetViewBounds.top;

    // put the item in the middle of the screen:
    int scrollToY = relativeTop - (scrollView.getHeight() / 2);
    if (scrollToY < 0) {
        scrollToY = 0;
    }

    return new Point(scrollView.getScrollX(), scrollToY);
}
 
Example 2
Source File: SlideBottomPanel.java    From pius1 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Copy From ScrollView (API Level >= 14)
 * <p>The scroll range of a scroll view is the overall height of all of its
 * children.</p>
 */
private int computeVerticalScrollRange(ScrollView scrollView) {
    final int count = scrollView.getChildCount();
    final int contentHeight = scrollView.getHeight() - scrollView.getPaddingBottom() - scrollView.getPaddingTop();
    if (count == 0) {
        return contentHeight;
    }

    int scrollRange = scrollView.getChildAt(0).getBottom();
    final int scrollY = scrollView.getScrollY();
    final int overScrollBottom = Math.max(0, scrollRange - contentHeight);
    if (scrollY < 0) {
        scrollRange -= scrollY;
    } else if (scrollY > overScrollBottom) {
        scrollRange += scrollY - overScrollBottom;
    }

    return scrollRange;
}
 
Example 3
Source File: PtrDefaultHandler2.java    From Elephant with Apache License 2.0 6 votes vote down vote up
public static boolean canChildScrollDown(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else if (view instanceof ScrollView) {
            ScrollView scrollView = (ScrollView) view;
            if (scrollView.getChildCount() == 0) {
                return false;
            } else {
                return scrollView.getScrollY() < scrollView.getChildAt(0).getHeight() - scrollView.getHeight();
            }
        } else {
            return false;
        }
    } else {
        return view.canScrollVertically(1);
    }
}
 
Example 4
Source File: PtrDefaultHandler2.java    From android-Ultra-Pull-To-Refresh-With-Load-More-master with MIT License 6 votes vote down vote up
public static boolean canChildScrollDown(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else if (view instanceof ScrollView) {
            ScrollView scrollView = (ScrollView) view;
            if (scrollView.getChildCount() == 0) {
                return false;
            } else {
                return scrollView.getScrollY() < scrollView.getChildAt(0).getHeight() - scrollView.getHeight();
            }
        } else {
            return false;
        }
    } else {
        return view.canScrollVertically(1);
    }
}
 
Example 5
Source File: Utils.java    From MaterialViewPager with Apache License 2.0 6 votes vote down vote up
static boolean canScroll(View view) {
    if (view instanceof ScrollView) {
        ScrollView scrollView = (ScrollView) view;
        View child = scrollView.getChildAt(0);
        if (child != null) {
            int childHeight = child.getHeight();
            return scrollView.getHeight() < childHeight + scrollView.getPaddingTop() + scrollView.getPaddingBottom();
        }
        return false;
    } else if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        int yOffset = recyclerView.computeVerticalScrollOffset();
        return yOffset != 0;
    }
    return true;
}
 
Example 6
Source File: ExpandableHeightExpandableListView.java    From Bluefruit_LE_Connect_Android with MIT License 6 votes vote down vote up
public void scrollToGroup(int groupPosition, View view, ScrollView parentScrollView){
    final float baseY = getY();
    final float currentGroupPosY = baseY + view.getY();
    final int currentScrollY = parentScrollView.getScrollY();
    final View nextGroupView = findViewWithTag(groupPosition+1);

    if (currentScrollY > currentGroupPosY) {
        parentScrollView.smoothScrollTo(parentScrollView.getScrollX(),  view.getTop());
    }
    else if (nextGroupView != null) {
        final float nextGroupPosY = baseY + nextGroupView.getY();
        if (currentScrollY + parentScrollView.getHeight() < nextGroupPosY) {
            parentScrollView.smoothScrollTo(0,  nextGroupView.getBottom());
        }
    }
    else {
        parentScrollView.smoothScrollTo(parentScrollView.getScrollX(), getBottom()-parentScrollView.getHeight());
    }
}
 
Example 7
Source File: SlideBottomPanel.java    From pius1 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *  Copy From ScrollView (API Level >= 14)
 * @param direction Negative to check scrolling up, positive to check
 *                  scrolling down.
 *   @return true if the scrollView can be scrolled in the specified direction,
 *         false otherwise
 */
private  boolean scrollViewCanScrollVertically(ScrollView scrollView,int direction) {
    final int offset = Math.max(0, scrollView.getScrollY());
    final int range = computeVerticalScrollRange(scrollView) - scrollView.getHeight();
    if (range == 0) return false;
    if (direction < 0) { //scroll up
        return offset > 0;
    } else {//scroll down
        return offset < range - 1;
    }
}
 
Example 8
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void scrollOnDrag(View view, DragEvent event, ScrollView scrollView) {
    float ty = view.getTop() + event.getY();

    if (isAncestor(scrollView, view)) {

        int thresh = scrollView.getHeight() / 6;

        if (ty < scrollView.getScrollY() + thresh) {
            scrollView.smoothScrollBy(0, -10);
        } else if (ty > scrollView.getScrollY() + scrollView.getHeight() - thresh) {
            scrollView.smoothScrollBy(0, 10);
        }
    }
}
 
Example 9
Source File: FixedSubmitBarLayout.java    From ResearchStack with Apache License 2.0 5 votes vote down vote up
private void onScrollChanged(ScrollView scrollView, View submitBarGuide, View submitBar) {
    int scrollY = scrollView.getScrollY();
    int guidePosition = submitBarGuide.getTop() - scrollY;
    int guideHeight = submitBarGuide.getHeight();
    int yLimit = scrollView.getHeight() - guideHeight;

    if (guidePosition <= yLimit) {
        ViewCompat.setTranslationY(submitBar, 0);
    } else {
        int translationY = guidePosition - yLimit;
        ViewCompat.setTranslationY(submitBar, translationY);
    }

}
 
Example 10
Source File: BounceTouchListener.java    From Bounce with Apache License 2.0 5 votes vote down vote up
private boolean hasHitBottom() {
    if (mMainView instanceof ScrollView) {
        ScrollView scrollView = (ScrollView) mMainView;
        View view = scrollView.getChildAt(scrollView.getChildCount() - 1);
        int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));// Calculate the scrolldiff
        return diff == 0;
    } else if (mMainView instanceof ListView) {
        ListView listView = (ListView) mMainView;
        if (listView.getAdapter() != null) {
            if (listView.getAdapter().getCount() > 0) {
                return listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1 &&
                        listView.getChildAt(listView.getChildCount() - 1).getBottom() <= listView.getHeight();
            }
        }
    } else if (mMainView instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) mMainView;
        if (recyclerView.getAdapter() != null && recyclerView.getLayoutManager() != null) {
            RecyclerView.Adapter adapter = recyclerView.getAdapter();
            if (adapter.getItemCount() > 0) {
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                if (layoutManager instanceof LinearLayoutManager) {
                    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
                    return linearLayoutManager.findLastCompletelyVisibleItemPosition() == adapter.getItemCount() - 1;
                } else if (layoutManager instanceof StaggeredGridLayoutManager) {
                    StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
                    int[] checks = staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(null);
                    for (int check : checks) {
                        if (check == adapter.getItemCount() - 1)
                            return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 11
Source File: DrMIPSActivity.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the state of the simulation controls and the values displayed.
 * Updates the enabled/disabled states of the simulation controls.
 * It also refreshes the values displayed in the tables and the datapath,
 * and scrolls the assembled code table to make the current instruction visible.
 */
private void refreshValues() {
	updateStepBackEnabled();
	updateStepEnabled();

	refreshRegistersTableValues();
	refreshDataMemoryTableValues();
	refreshAssembledCodeTableValues();
	refreshExecTableValues();
	if(datapath != null) datapath.refresh();

	// Scroll the assembled code table to the current instruction
	int index = getCPU().getPC().getCurrentInstructionIndex();
	if(index >= 0) {
		final ScrollView scroll = (ScrollView)findViewById(R.id.tblAssembledCodeScroll);
		final View row = tblAssembledCode.getChildAt(index + 1);

		// Scroll only if the row is out of view
		if(row != null && (row.getTop() < scroll.getScrollY() ||
		                   row.getBottom() > (scroll.getScrollY() + scroll.getHeight()))) {
			scroll.post(new Runnable() {
				@Override
				public void run() {
					if(row.getTop() < scroll.getScrollY()) {
						// Row is above the visible area
						// > scroll up until the row is visible at the top of the ScrollView
						scroll.smoothScrollTo(0, row.getTop());
					}
					else {
						// Row is below the visible area
						// > scroll down until the row is visible at the bottom of the ScrollView
						scroll.smoothScrollTo(0, row.getBottom() - scroll.getHeight());
					}
				}
			});
		}
	}
}