本文整理汇总了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
}