Android HorizontalScrollView左右滑动
效果图
一.什么是HorizontalScrollView
HorizontalScrollView实际上是一个FrameLayout ,这意味着你只能在它下面放置一个子控件 ,这个子控件可以包含很多数据内容。有可能这个子控件本身就是一个布局控件,可以包含非常多的其他用来展示数据的控件。这个布局控件一般使用的是一个水平布局的LinearLayout。TextView也是一个可滚动的视图控件,所以一般不需要HorizontalScrollView一般通过放置一个LinearLayout子控件。如果要使其添加其他的控件,就使用LinearLayout子控件来添加其他的控件,最后达到丰富其内容的效果。二.使用HorizontalScrollView实现左右滑动的效果
1.编写布局文件activity_main.xml
<?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:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.cxy.horizontalscrollview.MainActivity"> <HorizontalScrollView android