说明

ScrollView一个顶层布局可以实现大于手机屏幕布局,从而实现布局中的内容超过一屏显示不下时可自动页面提供上下滑动浏览功能

常用参数

示例代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:scrollbars="none"
 >
 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  >
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item1"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item2"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item3"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item4"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item5"
   />
 </LinearLayout>
 
</ScrollView>

注意事项

1,ScrollView控件是顶层控件尽量放在layout的最外层使用

2,ScrollView控件支持垂直滚动,如果要横向滚动请使用:HorizontalScrollView

3,ScrollView中只能包含一个控件,当超过一个app运行时会崩溃,切记!

4,如果ScrollView并非最外层的控件,请在ScrollView内部使用一个LinearLayout把这N个组件归在一起。务必!

常规使用方法

     通常是在〈ScrollView〉标签中定义一个<LinearLayout> 容器标签并且在<LinearLayout>标签中将android:orientation属性设置vertical,然后在<LinearLayout〉标签中放置多个控件,如果 <LinearLayout>标签中的控件所占用的总高度超出屏幕高度,就会 在屏幕右侧出现一个滚动条。 

原文地址:https://blog.csdn.net/wh445306/article/details/129496451

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_48300.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注