getScrollX ( )源码实例Demo

android.widget.HorizontalScrollView#getScrollX ( )源码实例Demo

下面列出了android.widget.HorizontalScrollView#getScrollX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  if (mLayoutDirection == LAYOUT_DIRECTION_RTL) {
    // When the layout direction is RTL, we expect Yoga to give us a layout
    // that extends off the screen to the left so we re-center it with left=0
    int newLeft = 0;
    int width = right - left;
    int newRight = newLeft + width;
    setLeft(newLeft);
    setRight(newRight);

    // Call with the present values in order to re-layout if necessary
    HorizontalScrollView parent = (HorizontalScrollView) getParent();
    // Fix the ScrollX position when using RTL language
    int offsetX = parent.getScrollX() + getWidth() - mCurrentWidth;
    parent.scrollTo(offsetX, parent.getScrollY());
  }
  mCurrentWidth = getWidth();
}
 
/**
 * Verify that 'scrollTo' command makes ScrollView start scrolling
 */
public void testScrollToCommand() throws Exception {
  HorizontalScrollView scrollView = getViewAtPath(0);
  ScrollViewTestModule jsModule =
      getReactContext().getCatalystInstance().getJSModule(ScrollViewTestModule.class);

  assertEquals(0, scrollView.getScrollX());

  jsModule.scrollTo(300, 0);
  waitForBridgeAndUIIdle();
  getInstrumentation().waitForIdleSync();

  // Unfortunately we need to use timeouts here in order to wait for scroll animation to happen
  // there is no better way (yet) for waiting for scroll animation to finish
  long timeout = 10000;
  long interval = 50;
  long start = System.currentTimeMillis();
  while (System.currentTimeMillis() - start < timeout) {
    if (scrollView.getScrollX() > 0) {
      break;
    }
    Thread.sleep(interval);
  }
  assertNotSame(0, scrollView.getScrollX());
}
 
源代码3 项目: LaunchTime   文件: MainActivity.java
private void hscrollOnDrag(View view, DragEvent event, HorizontalScrollView scrollView) {
    float tx = view.getLeft() + event.getX();

    if (isAncestor(scrollView, view)) {

        int thresh = scrollView.getWidth() / 6;

        if (tx < scrollView.getScrollX() + thresh) {
            scrollView.smoothScrollBy(-10, 0);
        } else if (tx > scrollView.getScrollX() + scrollView.getWidth() - thresh) {
            scrollView.smoothScrollBy(10,0);
        }
    }
}
 
@Test
public void testScrollAndClick() throws Throwable {
  final Activity activity = activityTestRule.getActivity();
  final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

  final Button button = activity.findViewById(R.id.button);
  final View.OnClickListener mockClickListener = mock(View.OnClickListener.class);
  button.setOnClickListener(mockClickListener);

  // Emulate a click on the button to verify that the registered listener is invoked
  // prior to performing a horizontal swipe across the app ba

  final int[] buttonXY = new int[2];
  button.getLocationOnScreen(buttonXY);
  final int buttonWidth = button.getWidth();
  final int buttonHeight = button.getHeight();
  final float emulatedTapX = buttonXY[0] + buttonWidth / 2.0f;
  final float emulatedTapY = buttonXY[1] + buttonHeight / 2.0f;

  emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY);
  verify(mockClickListener).onClick(button);
  reset(mockClickListener);

  final HorizontalScrollView hsv = activity.findViewById(R.id.hsv);
  final int scrollXBefore = hsv.getScrollX();
  // Now scroll / swipe horizontally across our scrollable content in the app bar
  onView(withId(R.id.app_bar)).perform(swipeLeft());
  assertTrue("Horizontal scroll performed", hsv.getScrollX() > scrollXBefore);

  // And emulate another click on the button to verify that the registered listener is still
  // invoked immediately after performing the horizontal swipe across the app bar
  emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY);
  verify(mockClickListener).onClick(button);
}
 
源代码5 项目: MiBandDecompiled   文件: x.java
public boolean canScrollHorizontal(View view, int i)
{
    HorizontalScrollView horizontalscrollview = (HorizontalScrollView)view;
    for (int j = horizontalscrollview.getScrollX(); horizontalscrollview.getChildCount() == 0 || (i >= 0 || j >= horizontalscrollview.getChildAt(0).getWidth() - horizontalscrollview.getWidth()) && (i <= 0 || j <= 0);)
    {
        return false;
    }

    return true;
}
 
源代码6 项目: APDE   文件: SketchFile.java
public FileChange getFileChange() {
	EditText code = fragment.getCodeEditText();
	
	if (code == null) {
		return null;
	}
	
	String codeText = code.getText().toString();
	
	if (!text.equals(codeText)) {
		HorizontalScrollView scrollerX = fragment.getCodeScrollerX();
		ScrollView scrollerY = fragment.getCodeScroller();
		
		FileChange change = new FileChange();
		
		getTextChange(change, text, codeText);
		
		change.beforeSelectionStart = selectionStart;
		change.beforeSelectionEnd = selectionEnd;
		
		change.afterSelectionStart = code.getSelectionStart();
		change.afterSelectionEnd = code.getSelectionEnd();
		
		change.beforeScrollX = scrollX;
		change.beforeScrollY = scrollY;
		
		change.afterScrollX = scrollerX.getScrollX();
		change.afterScrollY = scrollerY.getScrollY();
		
		return change;
	}
	
	return null;
}