问题描述
我正在使用 android studio,我有 xml 有水平滚动视图 然后线性布局然后多个图像视图..
<horizontalscrollview
android:id="@+id/horizontalscrollview1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
我需要的是让这个 horizantalscrollview 保持自动无限滚动图像直到最后,然后一次又一次地重复滚动。
我所说的自动滚动是什么意思,horizontalscrollview 在不用手的情况下继续滚动
解决方法
您是否尝试在 layout_width 中使用 wrap_content? 现在,你调整你的宽度布局以适应屏幕的宽度,我认为如果你把值 wrap_content 它会解决你的问题(你有 layout_height=wrap_content,但高度与垂直滚动“相关”,而不是与水平滚动滚动):
android:layout_width="wrap_content"
我希望这对你有帮助。
,好的谢谢你的支持..我找到了解决方案
Timer timer1 = new Timer("horizontalScrollViewTimer");
timer1.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (scrollingLeft) {
if (scroll.getScrollX() == 0) {
scroll.smoothScrollBy(5,0);
scrollingLeft = false;
} else {
scroll.smoothScrollBy(-5,0);
}
} else {
if (scroll.canScrollHorizontally(View.FOCUS_RIGHT)) {
scroll.smoothScrollBy(5,0);
} else {
scroll.smoothScrollBy(-5,0);
scrollingLeft = true;
}
}
}
});
}
},1000,50);