王学岗高级控件滚动视图(一)
2016-02-06 18:25
387 查看
<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=".MainActivity" > <ScrollView android:layout_width="match_parent" android:layout_height="200dp" android:background="#123456" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#abcdef" android:padding="100dp" android:text="张欣爱我一生一世" /> </ScrollView> </RelativeLayout>
添加了这句话
android:padding="100dp"才可以滑动,去掉不能滑动,如果把android:layout_height=”wrap_content”
改成android:layout_height=”500dp”
还是不能滑动。 所以我们得出一个结论,当ScrollView只有一个控件的时候,它的高度不起作用,能不能滚动取决于他内容的高度。如android:padding=”100dp”`就是改变了它的内容(内边距属于内容)。
`ScrollView只能有一个直接的儿子,多了会报错
我们在看一个典型的错误
在父容器ScrollView中写的是 android:layout_height=”wrap_content”
(父容器高度由子容器决定),而在LinearLayout中写的是android:layout_height=”match_parent”(子容器的高度由父容器决定),相互矛盾,会报错。
总结下
(1)对于ScrollView只有两种显示方式:充满父容器, 包裹类型
(2)当只有一个控件,而且控件的内容高度没有填充我们的ScrollView 那么设置控件的高度是没有效果的 (3)ScrollView能不能滚动,是由控件的内容高度决定的,不是由高度决定的。 (4)ScrollView只能有一个直接的子控件。 (5)ScrollView高度一般不要用wrap_content 直接子控件不要要用match_parent
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories