您的位置:首页 > 其它

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

2016-06-04 16:38 471 查看

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组件里面 最多只能包含一个组件

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: