本文整理了Java中android.widget.HorizontalScrollView.smoothScrollTo()
方法的一些代码示例,展示了HorizontalScrollView.smoothScrollTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HorizontalScrollView.smoothScrollTo()
方法的具体详情如下:
包路径:android.widget.HorizontalScrollView
类名称:HorizontalScrollView
方法名:smoothScrollTo
暂无
代码示例来源:origin: stackoverflow.com
private final void focusOnView(final HorizontalScrollView scroll, final View view) {
new Handler().post(new Runnable() {
@Override
public void run() {
int vLeft = view.getLeft();
int vRight = view.getRight();
int sWidth = scroll.getWidth();
scroll.smoothScrollTo(((vLeft + vRight - sWidth) / 2), 0);
}
});
}
代码示例来源:origin: stackoverflow.com
new Handler().postDelayed(new Runnable() {
public void run() {
horizontalScrollView.smoothScrollTo(
(int) horizontalScrollView.getScrollX()
+ viewWidth,
new Handler().postDelayed(new Runnable() {
public void run() {
horizontalScrollView.smoothScrollTo(
(int) horizontalScrollView.getScrollX()
- viewWidth,
horizontalScrollView.smoothScrollTo(layouts.get(currPosition)
.getLeft(), 0);
return true;
代码示例来源:origin: hackware1993/MagicIndicator
float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
if (mSmoothScroll) {
mScrollView.smoothScrollTo((int) (scrollTo), 0);
} else {
mScrollView.scrollTo((int) (scrollTo), 0);
mScrollView.smoothScrollTo(current.mLeft, 0);
} else {
mScrollView.scrollTo(current.mLeft, 0);
mScrollView.smoothScrollTo(current.mRight - getWidth(), 0);
} else {
mScrollView.scrollTo(current.mRight - getWidth(), 0);
代码示例来源:origin: stackoverflow.com
// Init variables
HorizontalScrollView mHS;
LinearLayout mLL;
// onCreateView method
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_container, container, false);
// Find your views
mHS = (HorizontalScrollView)view.findViewById(R.id.hscrollview);
mLL = (LinearLayout)view.findViewById(R.id.hscrollview_container);
// Do a Runnable on the inflated view
view.post(new Runnable() {
@Override
public void run() {
Log.v("","Left position of 12th child = "+mLL.getChildAt(11).getLeft());
mHS.smoothScrollTo(mLL.getChildAt(11).getLeft(), 0);
}
});
return view;
}
代码示例来源:origin: OCNYang/QBox
float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
if (mSmoothScroll) {
mScrollView.smoothScrollTo((int) (scrollTo), 0);
} else {
mScrollView.scrollTo((int) (scrollTo), 0);
mScrollView.smoothScrollTo(current.mLeft, 0);
} else {
mScrollView.scrollTo(current.mLeft, 0);
mScrollView.smoothScrollTo(current.mRight - getWidth(), 0);
} else {
mScrollView.scrollTo(current.mRight - getWidth(), 0);
代码示例来源:origin: jakebonk/BoardView
@Override
public void run() {
mRootLayout.smoothScrollTo(newX, 0);
}
});
代码示例来源:origin: quaap/LaunchTime
public void scrollToStart() {
mQuickRowScroller.smoothScrollTo(0, 0);
}
代码示例来源:origin: stackoverflow.com
public void onTabChanged(String tabId) {
for (int i = 0; i < tablist.length; i++) {
if (tabId.contentEquals(tablist[i])) {
HorizontalScrollView scroll = (HorizontalScrollView)findViewById(R.id.horScrollView);
scroll.smoothScrollTo(((int)(getResources().getDimensionPixelSize(R.dimen.tab_width) * (i))), 0);
}
}
代码示例来源:origin: stackoverflow.com
public void onResume() {
super.onResume();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
HorizontalScrollView sv = (HorizontalScrollView)findViewById(R.id.ScrollView01);
sv.smoothScrollTo(1000, 0);
}
}, 100);
}
代码示例来源:origin: KCrason/DynamicPagerIndicator
/**
* INDICATOR_MODE_SCROLLABLE 模式下,滑动条目居中显示
* 移动模式居中显示当前的条目
*/
public void transactionScrollTitleParentToCenter(int position) {
final int positionLeft = mTabParentView.getChildAt(position).getLeft();
final int positionWidth = mTabParentView.getChildAt(position).getWidth();
final int halfScreenWidth = Utils.calculateScreenWidth(mContext) / 2;
if (mAutoScrollHorizontalScrollView != null) {
mAutoScrollHorizontalScrollView.smoothScrollTo(positionLeft + positionWidth / 2 - halfScreenWidth, 0);
}
}
代码示例来源:origin: jjhesk/KickAssSlidingMenu
@Override
public void onClick(View v) {
Context context = menu.getContext();
String msg = "Slide " + new Date();
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
System.out.println(msg);
int menuWidth = menu.getMeasuredWidth();
// Ensure menu is visible
menu.setVisibility(View.VISIBLE);
if (!menuOut) {
// Scroll to 0 to reveal menu
int left = 0;
scrollView.smoothScrollTo(left, 0);
} else {
// Scroll to menuWidth so menu isn't on screen.
int left = menuWidth;
scrollView.smoothScrollTo(left, 0);
}
menuOut = !menuOut;
}
}
代码示例来源:origin: Tencent/RapidView
public void run(RapidParserObject object, Object view, Var value) {
List<String> list = RapidStringUtils.stringToList(value.getString());
if( list.size() < 2 ){
return;
}
((HorizontalScrollView)view).smoothScrollTo(Integer.parseInt(list.get(0)), Integer.parseInt(list.get(1)));
}
}
代码示例来源:origin: stackoverflow.com
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenWidth = metrics.widthPixels;
//get an instance of your LinearLayout, HSV, and ViewFlipper
LinearLayout ll = (LinearLayout)findViewById(R.id.my_linear_layout);
ViewFlipper vf = (ViewFlipper)findViewById(R.id.my_view_flipper);
HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.my_hsv);
//as you've said, there should always be an equal number of Buttons as
//Views in the ViewFlipper. This code assumes that is always true.
View v = ll.getChildAt(vf.getDisplayedChild());
//assuming smoothScrollTo scrolls to the left side of the screen,
//which I think it does, we want to scroll to the Button's center
//point, minus (shifted to the right) by half the screen width
int scrollTo = v.getLeft() + (v.getWidth() - screenWidth) / 2);
//handle overflow for the edge cases
if (scrollTo < 0) scrollTo = 0;
else if (scrollTo > hsv.getWidth()) scrollTo = hsv.getWidth();
hsv.smoothScrollTo(scrollTo);
代码示例来源:origin: stackoverflow.com
HorizontalScrollView calendarScroller = (HorizontalScrollView)findViewById(R.id.calendarScroller);
Handler handler=new Handler();
Runnable mTabSelector = new Runnable() {
public void run() {
View tabView = dateScroller.getChildAt(selectedDateIndex);// selected child view
final int scrollPos = tabView.getLeft() - (calendarScroller.getWidth() - tabView.getWidth()) / 2;
calendarScroller.smoothScrollTo(scrollPos, 0);
// mTabSelector = null;
}
};
handler.postDelayed(mTabSelector, 10);
代码示例来源:origin: wanliyang1990/NavigationBar
@Override
public void onClick(View v) {
if(cuPosition == index)
{
horizontalScrollView.smoothScrollTo(index * dip2px(getContext(), twidth) - leftm, 0);
}
if(margleft == 0)
{
viewPager.setCurrentItem(index, smoothScroll);
}
else {
viewPager.setCurrentItem(index, false);
}
if(onTitleClickListener != null)
{
onTitleClickListener.onTitleClick(v);
}
}
});
代码示例来源:origin: wanliyang1990/NavigationBar
@Override
public void onPageSelected(int position) {
cuPosition = position;
setSelectedTxtColor(context, setectedcolor, txtSelectedSize, position);
if(position == 0)
{
leftm = 0;
}
else
{
leftm = margleft;
}
horizontalScrollView.smoothScrollTo(position * dip2px(context, twidth) - leftm, 0);
if(onNaPageChangeListener != null)
{
onNaPageChangeListener.onPageSelected(position);
}
}
代码示例来源:origin: stackoverflow.com
HorizontalScrollView scroller;
int scrollerWidth = scroller.getMeasuredWidth();
int scrollX = scroller.getScrollX();
int activeViewCount = 0;
activeViewCount = (activeViewCount > 0) ? activeViewCount - 1 : 0;
scroller.smoothScrollTo(activeViewCount * scrollerWidth, 0);
if (scrollX >= scrollerWidth) {
scroller.scrollTo(0, 0);
}
代码示例来源:origin: Calsign/APDE
public void scrollToChar(int pos, EditorActivity editor) {
float xOffset = getCompoundPaddingLeft();
//Calculate coordinates
int x = (int) Math.max(xOffset + getLayout().getPrimaryHorizontal(pos), 1);
int y = getLineHeight() * getLayout().getLineForOffset(pos);
((HorizontalScrollView) editor.findViewById(R.id.code_scroller_x)).smoothScrollTo(x, 0);
((ScrollView) editor.findViewById(R.id.code_scroller)).smoothScrollTo(0, y);
}
代码示例来源:origin: Catrobat/Paintroid
@Override
public void scrollToButton(ToolType toolType, boolean animate) {
View buttonView = layout.findViewById(toolType.getToolButtonID());
switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
ScrollView verticalScrollView = (ScrollView) scrollView;
int destinationY = getViewCenterYInScrollView(scrollView, buttonView);
if (animate) {
verticalScrollView.smoothScrollTo(0, destinationY);
} else {
verticalScrollView.scrollTo(0, destinationY);
}
break;
case Configuration.ORIENTATION_PORTRAIT:
default:
HorizontalScrollView horizontalScrollView = (HorizontalScrollView) scrollView;
int destinationX = getViewCenterXInScrollView(scrollView, buttonView);
if (animate) {
horizontalScrollView.smoothScrollTo(destinationX, 0);
} else {
horizontalScrollView.scrollTo(destinationX, 0);
}
break;
}
}
代码示例来源:origin: stackoverflow.com
private EditText mEditText;
private HorizontalScrollView mScrollView;
private void init() {
mEditText = (EditText) findViewById(R.id.TEXT_STATUS_ID);
mScrollView = (HorizontalScrollView) findViewById(R.id.SCROLLER_ID);
// loadDoc();
String s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
+ "Aliquam tempus convallis metus, ac congue dui elementum ut."
+ "Suspendisse rutrum non sapien feugiat fermentum."
+ "Phasellus vulputate quam in sapien vulputate venenatis."
+ "Pellentesque porta tincidunt nisi, et scelerisque augue facilisis nec."
+ "Curabitur eget risus quam."
+ "Maecenas pellentesque egestas enim, in ornare nisl lobortis id."
+ "Nunc vitae facilisis libero, vitae porttitor tellus.";
mEditText.setText(s);
scrollToBottom();
}
private void scrollToBottom() {
mScrollView.post(new Runnable() {
public void run() {
mEditText.setHorizontallyScrolling(true);
mEditText.setMovementMethod(new ScrollingMovementMethod());
mScrollView.smoothScrollTo(0, mEditText.getBottom());
}
});
}
内容来源于网络,如有侵权,请联系作者删除!