List of usage examples for android.widget ScrollView getLocationOnScreen
public void getLocationOnScreen(@Size(2) int[] outLocation)
Computes the coordinates of this view on the screen.
From source file:org.catrobat.paintroid.test.integration.BaseIntegrationTestClass.java
private void scrollToolBarToTop() { ScrollView scrollView = (ScrollView) mSolo.getView(R.id.bottom_bar_landscape_scroll_view); int[] screenLocation = { 0, 0 }; scrollView.getLocationOnScreen(screenLocation); int getAwayFromTop = 42; float fromY = screenLocation[1] + getAwayFromTop; float toY = scrollView.getHeight(); float xPos = screenLocation[0] + (scrollView.getWidth() / 2.0f); mSolo.drag(xPos, xPos, fromY, toY, 1); }
From source file:jp.mydns.sys1yagi.android.viewsticker.ViewSticker.java
private ViewGroup wrap(final View target, final ScrollView monitored, final ViewGroup container) { ViewGroup parent = (ViewGroup) target.getParent(); int index = parent.indexOfChild(target); parent.removeView(target);//w w w . j a v a2 s. c o m final int[] dimension = new int[2]; FrameLayout stuffing = new FrameLayout(target.getContext()) { ViewTreeObserver.OnScrollChangedListener mObserver = new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { monitored.getLocationOnScreen(dimension); int offset = dimension[1]; getLocationOnScreen(dimension); int top = dimension[1] - offset; offset(target, top); if (top < 0 && indexOfChild(target) >= 0) { removeView(target); container.addView(target); } else if (top >= 0 && indexOfChild(target) < 0) { container.removeView(target); addView(target); } } }; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec); measureChildWithMargins(target, widthMeasureSpec, 0, heightMeasureSpec, 0); setMeasuredDimension(widthSpecSize, heightSpecSize + target.getMeasuredHeight()); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); monitored.getViewTreeObserver().addOnScrollChangedListener(mObserver); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); monitored.getViewTreeObserver().removeOnScrollChangedListener(mObserver); } }; stuffing.addView(target); parent.addView(stuffing, index); return stuffing; }