Linux 拨号vps windows公众号手机端

Android中scrollview怎么实现水平滑动

lewis 9年前 (2017-02-04) 阅读数 12 #程序编程
文章标签 android

要实现水平滑动的ScrollView,你可以使用HorizontalScrollView来代替ScrollView。HorizontalScrollView是Android提供的用于水平滑动的容器。

以下是一个简单的示例代码:

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <!-- 这里放置需要水平滑动的子视图 -->

    </LinearLayout>

</HorizontalScrollView>

在上面的代码中,我们使用了一个HorizontalScrollView作为外层容器,然后在内部放置了一个LinearLayout作为子视图容器,可以在LinearLayout内部放置需要水平滑动的子视图。

注意:HorizontalScrollView只能有一个子视图,所以你需要在LinearLayout内部添加需要滑动的子视图。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门