【问题标题】:Scroll on clicking next and back button in android滚动单击android中的下一步和后退按钮
【发布时间】:2012-09-22 07:24:56
【问题描述】:

我有一个与在 android 中滚动相关的小问题。这是我的xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<VideoView 
    android:layout_height="match_parent"
    android:layout_width="fill_parent"
    android:id="@+id/video"
    />

<RelativeLayout 
    android:layout_width="fill_parent"      
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:visibility="invisible"
    android:id="@+id/channelview" >

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/back"
        android:layout_alignParentLeft="true"
        android:id="@+id/backbtn"
        />

    <HorizontalScrollView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/backbtn"
        android:layout_toLeftOf="@+id/nextbtn"
        android:id="@+id/scroll" >

        <LinearLayout
            android:id="@+id/imageholder"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal" >
        </LinearLayout>
    </HorizontalScrollView>

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/next"
        android:layout_alignParentRight="true"
        android:id="@+id/nextbtn"
        />

</RelativeLayout>    

问题是我正在向线性布局动态添加 Imageviews(超过 50 个),我不确定如何通过单击水平滚动视图两侧添加的下一个和上一个按钮来使其滚动。默认情况下,如果我在滚动视图上滑动它会滚动,但我也想通过单击按钮来滚动任何一种方式。谁能建议我如何使用示例代码完成它。谢谢。

【问题讨论】:

  • 嗨,我知道这个问题已经很老了。但我是否也在寻找相同的功能。你找到解决办法了吗?

标签: android android-layout button scroll scrollview


【解决方案1】:

这样滚动视图可以向上或向下滚动。

scrollview.post(new Runnable() {

    @Override
    public void run() {
        // to scroll down
        scrollview.fullScroll(ScrollView.FOCUS_DOWN);
        // to scroll up
        scrollview.fullScroll(ScrollView.FOCUS_UP);
    }
});

【讨论】:

  • 这将使它转到视图的极端顶部或极端底部。我只是想让它提前几个量。
猜你喜欢
  • 2011-12-06
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多