<ScrollView> 滚动视图的简单功能和用法

来源:互联网 发布:淘宝店铺粉丝最多 编辑:程序博客网 时间:2024/06/05 16:28

ScrollView是由Framelayout派生出来的,它就是一个用于为普通组件添加滚动条的组件.ScrollView里最多只能包含一个组件,而ScrollView的作用就是为组件添加垂直滚动条.

package com.crazyit.ui.scrollviewdemo;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;/** * ScrollView 的功能与简单用法 */public class ScrollViewActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_scroll_view);    }}

布局文件

<?xml version="1.0" encoding="utf-8"?><!--定义ScrollView 为里面的组件添加垂直滚动条--><ScrollView 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="com.crazyit.ui.scrollviewdemo.ScrollViewActivity">    <HorizontalScrollView        android:layout_width="match_parent"        android:layout_height="wrap_content"        >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Hello World!" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Hello World!" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Hello World!" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="滚动视图滚动视图滚动视图滚动视图"                android:textSize="30dp" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Hello World!" />        </LinearLayout>    </HorizontalScrollView></ScrollView>

ScrollView组件里面 最多只能包含一个组件

0 0
原创粉丝点击