<?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>
效果图: