Android添加垂直滚动ScrollView

来源:互联网 发布:c语言换行符号 编辑:程序博客网 时间:2024/05/23 18:22

Android添加垂直滚动ScrollView


界面的内容太多了,想在Android里面添加滚动效果,就是在LinearLayout外面添加一个ScrollView就行了 。
由:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <LinearLayout  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:tools="http://schemas.android.com/tools"  
  5.     android:orientation="vertical"  
  6.     android:layout_width="fill_parent"  
  7.     android:layout_height="fill_parent"  
  8.     tools:context=".MainActivity">  
  9. </LinearLayout>  
到:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <ScrollView    
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:tools="http://schemas.android.com/tools"  
  5.     android:layout_width="fill_parent"    
  6.     android:layout_height="fill_parent"    
  7.     android:scrollbars="vertical"    
  8.     android:fadingEdge="vertical">  
  9.     <LinearLayout  
  10.         xmlns:android="http://schemas.android.com/apk/res/android"  
  11.         xmlns:tools="http://schemas.android.com/tools"  
  12.         android:orientation="vertical"  
  13.         android:layout_width="fill_parent"  
  14.         android:layout_height="fill_parent"  
  15.         tools:context=".MainActivity">  
  16.     </LinearLayout>  
  17. </ScrollView>  

结果在第10行11行出现了一个Error:

Unexpected namespace prefix "xmlns" found for tag LinearLayout

后来发现

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. xmlns:android="http://schemas.android.com/apk/res/android"  
必须作为第一个节点的属性,于是把LinearLayout的xmlns:android和xmlns:tools这两个属性去掉就可以了。

成为:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <ScrollView    
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:tools="http://schemas.android.com/tools"  
  5.     android:layout_width="fill_parent"    
  6.     android:layout_height="fill_parent"    
  7.     android:scrollbars="vertical"    
  8.     android:fadingEdge="vertical">  
  9.     <LinearLayout  
  10.         android:orientation="vertical"  
  11.         android:layout_width="fill_parent"  
  12.         android:layout_height="fill_parent"  
  13.         tools:context=".MainActivity">  
  14.     </LinearLayout>  
  15. </ScrollView>  
0 0
原创粉丝点击