1.ScrollView也是一个容器,它是FrameLayout的子类,它的主要作用就是将超出物理屏幕的内容显示出来,(就是滚动条效果)ScrollView提供垂直滚动,进而可将超出物理屏幕的内容显示出来。 1.1.2首先给按钮设置id,其次页面的内容必须长,否则跳转不到另一个页面 1.1.3用到了 <scrollView></scrollView> 2.ScrollView只提供了垂直滚动条,若要使用水平滚动功能,则Android提供了HorizontalScrollView容器,HorizontalScrollView容器可以提供水平滚动,它的使用方法与ScrollView类似 这是页面代码 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="跳转底部 " /> <Button android:id="@+id/btn_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="返回顶部" /> </LinearLayout> <ScrollView android:id="@+id/sv" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="顶部" />
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本2" /> <TextView
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="底部" /> </LinearLayout> </ScrollView> 这是后端代码
// 对于监听的处理 @Override public void onClick(View v) { if (v.getId() == R.id.btn_top) { // 返回顶部 scrollView.fullScroll(ScrollView.FOCUS_UP); } else if (v.getId() == R.id.btn_bottom) { // 跳转底部 scrollView.fullScroll(ScrollView.FOCUS_DOWN); } else { }