HorizontalScrollView的基本使用,适合初学者

这篇博客适合初学者,介绍了HorizontalScrollView的基础使用。通过示例代码展示了如何在XML布局中添加HorizontalScrollView,以及如何实现简单的滑动效果。同时提到了去除滚动进度条以提升用户体验的问题。

 HorizontalScrollView是一个 FrameLayout

本人小白,不知道怎么会解释,看的懂会用就行了

废话就不说了,直接看代码。。。。。。。。

直接在activity_main.xml里添加HorizontalScrollView控件,源代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.administrator.horizontalscrollview.MainActivity">

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

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

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#ff00ff" />

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#000000" />

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#b7a500" />

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#c1070e" />

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#ff00ff" />

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#000000" />

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#b7a500" />

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="#c1070e" />

        </LinearLayout>


    </HorizontalScrollView>
</RelativeLayout>

效果图:




简单的滑动效果,这样看起来不美观,有一个滑动进度条, 影响用户体验差,所以为了去掉进度条可以在

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none">
里添加添加
android:scrollbars="none"
这一属性,就可以去掉了进度条了
添加属性后的效果:

 



评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值