[Android] 009_ScrollView移动屏幕的使用方法

Android_009_ScrollView移动屏幕的使用方法

1. 要想让屏幕能能移动显示多于一屏的内容时, 我们就可以利用在”布局文件”中插入<scrollView></scrollviet>. 仅仅只需要修改布局文件即可.

例子: 有20个按钮要显示在一个 Activity中, 通知移动屏幕可以选择所有的按钮.

布局文件main.xml中的代码为:

View Code
<? xml version="1.0" encoding="utf-8" ?>
< ScrollView  xmlns:android ="http://schemas.android.com/apk/res/android"
    android:layout_width
="fill_parent"
    android:layout_height
="fill_parent"
    android:scrollbars
="vertical"
    android:fadingEdge
="vertical"
    
>
    
< LinearLayout 
        
android:orientation ="vertical"
        android:layout_width
="fill_parent"
        android:layout_height
="fill_parent"
        
>
        
< Button 
            
android:id ="@+id/lesson1"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson1"
            
/>
        
< Button 
            
android:id ="@+id/lesson2"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson2"
            
/>
        
< Button 
            
android:id ="@+id/lesson3"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson3"
            
/>
        
< Button 
            
android:id ="@+id/lesson4"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson4"
            
/>
        
< Button 
            
android:id ="@+id/lesson5"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson5"
            
/>
        
< Button 
            
android:id ="@+id/lesson6"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson6"
            
/>
        
< Button 
            
android:id ="@+id/lesson7"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson7"
            
/>
        
< Button 
            
android:id ="@+id/lesson8"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson8"
            
/>
        
< Button 
            
android:id ="@+id/lesson9"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson9"
            
/>
        
< Button 
            
android:id ="@+id/lesson10"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson10"
            
/>
        
< Button 
            
android:id ="@+id/lesson11"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson11"
            
/>
        
< Button 
            
android:id ="@+id/lesson12"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson12"
            
/>
        
< Button 
            
android:id ="@+id/lesson13"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson13"
            
/>
        
< Button 
            
android:id ="@+id/lesson14"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson14"
            
/>
        
< Button 
            
android:id ="@+id/lesson15"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson15"
            
/>
        
< Button 
            
android:id ="@+id/lesson16"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson16"
            
/>
        
< Button 
            
android:id ="@+id/lesson17"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson17"
            
/>
        
< Button 
            
android:id ="@+id/lesson18"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson18"
            
/>
        
< Button 
            
android:id ="@+id/lesson19"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson19"
            
/>
        
< Button 
            
android:id ="@+id/lesson20"
            android:layout_width
="fill_parent"
            android:layout_height
="wrap_content"
            android:text
="lesson20"
            
/>
    
</ LinearLayout >
</ ScrollView >

显示结果如下:

clip_image001

利用方向键向下移动屏幕, 就可以看到剩下的按钮:

clip_image002

转载于:https://www.cnblogs.com/shanhaiyang/archive/2011/07/13/2104812.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值