本文整理匯總了Java中android.widget.HorizontalScrollView.getScrollX方法的典型用法代碼示例。如果您正苦於以下問題:Java HorizontalScrollView.getScrollX方法的具體用法?Java HorizontalScrollView.getScrollX怎麽用?Java HorizontalScrollView.getScrollX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.HorizontalScrollView
的用法示例。
在下文中一共展示了HorizontalScrollView.getScrollX方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testScrollToCommand
import android.widget.HorizontalScrollView; //導入方法依賴的package包/類
/**
* 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());
}
示例2: hscrollOnDrag
import android.widget.HorizontalScrollView; //導入方法依賴的package包/類
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);
}
}
}
示例3: testScrollAndClick
import android.widget.HorizontalScrollView; //導入方法依賴的package包/類
@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);
}
開發者ID:material-components,項目名稱:material-components-android,代碼行數:35,代碼來源:AppBarHorizontalScrollingTest.java