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"
这一属性,就可以去掉了进度条了
添加属性后的效果:
这篇博客适合初学者,介绍了HorizontalScrollView的基础使用。通过示例代码展示了如何在XML布局中添加HorizontalScrollView,以及如何实现简单的滑动效果。同时提到了去除滚动进度条以提升用户体验的问题。
566





