List of usage examples for android.widget HorizontalScrollView smoothScrollTo
public final void smoothScrollTo(int x, int y)
From source file:org.orange.querysystem.content.TabsAdapter.java
public void adjustSelectedTabToCenter() { View currentTab = mTabHost.getCurrentTabView(); if (currentTab == null) { return;/*from w w w. j ava 2 s . c o m*/ } HorizontalScrollView hsv = (HorizontalScrollView) mTabHost.findViewById(R.id.tabs_scroll); hsv.smoothScrollTo(currentTab.getLeft() + (currentTab.getWidth() - hsv.getWidth()) / 2, 0); }
From source file:org.catrobat.paintroid.ui.BottomBar.java
private void scrollToSelectedTool(ToolType toolType) { int orientation = mMainActivity.getResources().getConfiguration().orientation; View toolButton = getToolButtonByToolType(toolType); if (orientation == Configuration.ORIENTATION_PORTRAIT) { HorizontalScrollView scrollView = (HorizontalScrollView) mMainActivity .findViewById(R.id.bottom_bar_scroll_view); scrollView.smoothScrollTo( (int) (toolButton.getX() - scrollView.getWidth() / 2.0f + toolButton.getWidth() / 2.0f), (int) toolButton.getY()); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { ScrollView scrollView = (ScrollView) mMainActivity.findViewById(R.id.bottom_bar_landscape_scroll_view); scrollView.smoothScrollTo((int) (toolButton.getX()), (int) (toolButton.getY() - scrollView.getHeight() / 2.0f + toolButton.getHeight() / 2.0f)); }//from www .ja v a 2 s . c om }
From source file:com.mobicage.rogerthat.plugins.friends.ServiceSearchActivity.java
private void displayTab(int tab) { final int childCount = mSearchCategoryViewFlipper.getChildCount(); if (childCount == 0) { return;/* w w w.j av a2 s.c o m*/ } while (tab < 0) tab += childCount; tab = tab % childCount; mSearchCategoryViewFlipper.setDisplayedChild(tab); for (int i = 0; i < childCount; i++) { SearchInfo si = mSearchInfoByListView.get(mSearchCategoryViewFlipper.getChildAt(i)); if (si == null) { L.bug("Could not find list view!"); return; } final boolean selected = tab == i; final LinearLayout v = si.label; setCatorySelected(v, selected); if (selected) { final HorizontalScrollView sv = (HorizontalScrollView) findViewById( R.id.search_category_scroll_container); sv.post(new SafeRunnable() { @Override public void safeRun() { int vLeft = v.getLeft(); int vRight = v.getRight(); int width = v.getWidth(); sv.smoothScrollTo(((vLeft + vRight) / 2) - (width), 0); } }); } } }
From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java
/** * changes the page./* www .j a v a 2 s .c o m*/ * * @param position the page to go to. * @param clicked if true, the viewPager is set to the position */ private void changePage(final int position, boolean clicked, boolean force) { if (images.size() > 1 && (force || current != position)) { Log.d("SEND_IMAGE", "page changed"); images.get(current).getBackground().setVisibility(View.GONE); images.get(position).getBackground().setVisibility(View.VISIBLE); current = position; // scroll to correct position HorizontalScrollView scrollView = (HorizontalScrollView) getActivity() .findViewById(R.id.send_image_overview); View view = images.get(current).getLayout(); int vLeft = view.getLeft(); int vRight = view.getRight(); int sWidth = scrollView.getWidth(); if (!isViewVisible(scrollView, view)) scrollView.smoothScrollTo((vLeft + vRight - sWidth) / 2, 0); if (clicked) // setting the viewPagers item is posted via a handler, so the gui // thread finishes the scrollView related task before switching the // viewPager. That way it seems smoother because the new image is // selected instantly. new Handler().post(new Runnable() { @Override public void run() { viewPager.setCurrentItem(position); } }); } }
From source file:org.xbmc.android.remotesandbox.ui.BaseFragmentTabsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final long start = System.currentTimeMillis(); Log.d(TAG, "Starting onCreate()..."); setContentView(R.layout.activity_fragment_tabs_pager); final HorizontalScrollView scroller = (HorizontalScrollView) findViewById(R.id.tab_scroller); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabWidget = (TabWidget) findViewById(android.R.id.tabs); mViewPager = (ViewPager) findViewById(R.id.tab_pager); mTabHost.setup();/*w w w .j a v a2 s . com*/ mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager); getActivityHelper().setupActionBar(getTitle(), 0); final String customTitle = getIntent().getStringExtra(Intent.EXTRA_TITLE); getActivityHelper().setActionBarTitle(customTitle != null ? customTitle : getTitle()); if (savedInstanceState == null) { onCreateTabs(); //mFragment = onCreatePane(); //mFragment.setArguments(intentToFragmentArguments(getIntent())); } else { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); } mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { final int position = mTabHost.getCurrentTab(); final View tab = mTabWidget.getChildTabViewAt(position); scroller.smoothScrollTo(tab.getLeft(), 0); mViewPager.setCurrentItem(position); } }); Log.d(TAG, "onCreate() done in " + (System.currentTimeMillis() - start) + "ms."); }