移动HorizontalScrollView滚动条

有什么方式,可移动滚动条,且按百分比.
就是,每01.秒走1%的滚动条.
在线等。。。谢谢。。。

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hscroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="horizontal"
android:fadingEdge="horizontal">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/text_view"
android:textColor="#F05"
android:textSize="100px"
android:singleLine="true"
android:paddingTop="5dip" />
</HorizontalScrollView>
HorizontalScrollView 是 Android 中的一个视图组件,用于水平滚动显示内容。如果你想让 HorizontalScrollView 滚动到指定的子项,通常你需要以下几个步骤: 1. **获取 Scroll View 和 Child Views**: 首先,你需要找到 HorizontalScrollView 对象,并获取其包含的所有子 view。你可以通过 `findViewByTag()` 或者遍历 `scrollview.getChildAt()` 来获取。 ```java HorizontalScrollView scrollView = findViewById(R.id.horizontalscrollView); LinearLayout layout = (LinearLayout) scrollView.getChildAt(index); // index 是你想滚动到的子项位置 ``` 2. **测量并计算滚动偏移量**: 计算目标子项的位置相对于 HorizontalScrollView 的起始点所需要的滚动距离。这通常涉及到对子项的宽度和已知的滚动容器尺寸的计算。 ```java int itemWidth = layout.getWidth(); int scrollOffset = itemWidth * index; // 按照子项宽度来计算滚动位置 ``` 3. **设置滚动视图**: 使用 `smoothScrollTo()` 方法平滑地滚动到指定位置。如果需要动画效果,可以传递一个时间参数;如果没有动画需求,可以传入 `0`。 ```java scrollView.smoothScrollTo(0, scrollOffset); ``` 4. **处理边界情况**: 确保不会因为滚动超出范围而出现问题,可以在滚动之前检查当前滚动位置以及目标位置是否超出可视区域。 ```java if (scrollOffset < 0 || scrollOffset > scrollView.getWidth() - layout.getWidth()) { // 调整滚动位置到合适的范围内 } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值