本文整理匯總了Java中android.widget.HorizontalScrollView.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java HorizontalScrollView.getWidth方法的具體用法?Java HorizontalScrollView.getWidth怎麽用?Java HorizontalScrollView.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.HorizontalScrollView
的用法示例。
在下文中一共展示了HorizontalScrollView.getWidth方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
}
示例2: changePage
import android.widget.HorizontalScrollView; //導入方法依賴的package包/類
/**
* changes the page.
*
* @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);
}
});
}
}
示例3: onTabChanged
import android.widget.HorizontalScrollView; //導入方法依賴的package包/類
public void onTabChanged(String tabId){
int selectedItem = tabHost.getCurrentTab();
viewPager.setCurrentItem(selectedItem);
//View rootView= inflater.inflate(R.layout.fragment_first_aid, container, false);
HorizontalScrollView hScrollView = (HorizontalScrollView) rootView.findViewById(R.id.h_scroll_view);
View tabView = tabHost.getCurrentTabView();
int scrollPos = tabView.getLeft()-(hScrollView.getWidth()-tabView.getWidth())/2;
hScrollView.smoothScrollTo(scrollPos,0);
//32.28
}