【问题标题】:Android studio automatic horizontalscrollview infinite scrolling till end then repeatAndroid studio自动horizo​​ntalscrollview无限滚动直到结束然后重复
【发布时间】:2021-09-05 11:05:00
【问题描述】:

我正在使用 android studio,我有 xml,它有 Horizo​​ntalscrollview 然后是线性布局,然后是多个图像视图..

<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 自动无限滚动图像直到结束,然后一次又一次地重复滚动。

我的意思是自动滚动水平滚动视图在不使用手的情况下保持滚动

【问题讨论】:

    标签: java android-studio imageview horizontalscrollview autoscroll


    【解决方案1】:

    您是否尝试在 layout_width 中使用 wrap_content? 现在,你让你的宽度布局适应屏幕的宽度,我认为如果你把值 wrap_content 它将解决你的问题(你有 layout_height=wrap_content,但高度与垂直滚动“相关”,而不是与水平滚动):

    android:layout_width="wrap_content"
    

    希望对你有所帮助。

    【讨论】:

    • horizo​​ntalscroll 视图工作没有问题,我只需要手动滚动而不是手动滚动它,从头到尾自动滚动并不断重复
    • 对不起,我没听懂你的意思。看看这个链接:android-arsenal.com/details/1/7907我想这是你想做的。
    【解决方案2】:

    好的,感谢您的支持..我找到了解决方案

        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);
    

    【讨论】:

      猜你喜欢
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 2011-06-10
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      相关资源
      最近更新 更多