Android基础控件ScrollView滚动条的使用
1、简介
ScrollView是一个FrameLayout的容器,不过在他的基础上添加了滚动,允许显示的比实际多的内容!另外,只能够往里面放置一个子元素,可以是单一的组件,又或者一个布局包裹着的复杂的层次结构!或者我们应该叫它竖直滚动条,对应的另外一个水平方向上的滚动条:HorizontalScrollView。
android:scrollbarThumbVertical //设置竖直滑块
android:scrollbarThumbHorizontal //设置水平滑块
android:scrollbars //设置滑块显示样式(水平、竖直、不显示)
@Override //重写滑动速度
public void fling(int velocityY) {
super.fling(velocityY / 2); //速度变为原来的一半
}
scrollView.fullScroll(ScrollView.FOCUS_DOWN); //滚动到底部
scrollView.fullScroll(ScrollView.FOCUS_UP); //滚动到顶部
2、简单使用

布局xml文件:
<LinearLayout 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"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LoginActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn11"
android:text="最底部"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn22"
android:text="最顶部"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollview"
android:scrollbarThumbVertical="@drawable/rating_on"
android:scrollbars="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"/>
</ScrollView>
</LinearLayout>
Java文件:
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
private ScrollView scrollView;
private TextView textView;
private Button btn_up;
private Button btn_down;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Set up the login form.
scrollView = (ScrollView)findViewById(R.id.scrollview);
textView = (TextView)findViewById(R.id.textview);
btn_down = (Button)findViewById(R.id.btn11);
btn_up = (Button)findViewById(R.id.btn22);
btn_up.setOnClickListener(this);
btn_down.setOnClickListener(this);
StringBuilder stringBuilder = new StringBuilder();
for (int i=0;i<100;i++){
stringBuilder.append("这是scrollview"+i+"\n");
}
textView.setText(stringBuilder.toString());
}
public void onClick(View v){
switch (v.getId()){
case R.id.btn11:
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
break;
case R.id.btn22:
scrollView.fullScroll(ScrollView.FOCUS_UP);
break;
}
}
}
Android基础控件ScrollView滚动条的使用的更多相关文章
- Android基础控件ListView基础操作
1.简介 基于Android基础控件ListView和自定义BaseAdapter适配器情况下,对ListView的数据删除和添加操作: public boolean add(E e) {//添加数据 ...
- android 基础控件(EditView、SeekBar等)的属性及使用方法
android提供了大量的UI控件,本文将介绍TextView.ImageView.Button.EditView.ProgressBar.SeekBar.ScrollView.WebView ...
- 矩阵, 矩阵 , Android基础控件之ImageView
天下文章大家抄,以下所有内容,有来自copy,有来自查询,亦有自己的总结(目的是总结出自己的东西),所以说原创,不合适,说是转载也不恰当,所以我称之为笔记,可惜没有此分类选项,姑且不要脸一点,选择为原 ...
- android 基础控件 EditText
EditText 简介: EditText 控件继承 TextView ,它有TextView的所有属性和方法,并且自身是可编辑的: extends TextView java.lang.Object ...
- Android 基础控件 TextView
一TextView介绍: TextView是UI最基本的组件,使用TextView可以显示丰富的文本信息.设置添加TextView最常见的方法就是在xml中添加TextView元素,并指定属性.Tex ...
- Android基础控件TextClock和Chronometer的使用
1.简介 DigitalClock, TextClock,AnalogClock,Chronometer其中DigitalClock和AnalogClock废弃了! TextClock是在Androi ...
- Android基础控件ProgressBar进度条的使用
1.简介 ProgressBar继承与View类,直接子类有AbsSeekBar和ContentLoadingProgressBar, 其中AbsSeekBar的子类有SeekBar和RatingBa ...
- Android基础控件单选按钮RadioButton和Checkbox复选按钮的使用
1.相关简介 RadioButton需要和RadioGroup结合使用,在RadioGroup设置布局方式! Checkbox是单独使用,本文为了方便放在了RadioGroup中! 2.简单使用 方法 ...
- Android基础控件Button的使用
1.相关属性 Android的按钮有Button和ImageButton(图像按钮),Button extends TextView, ImageButton extends ImageView! a ...
随机推荐
- 《转》python对象
http://www.cnblogs.com/BeginMan/p/3160044.html 一.学习目录 1.pyhton对象 2.python类型 3.类型操作符与内建函数 4.类型工厂函数 5. ...
- 第四天:语句、表达式与if分支、循环语句
表达式 代码风格 代码格式指南 PEP8 缩进4空格 一行不超过79 空行 赋值语句 基本 (x,y) = (5,10) x [x,y,z] = [1,2,3] x a,b,c = 'uhk' a 5 ...
- Android笔记之RoundedImageView
参考项目:GcsSloop/rclayout 实现1,利用Canvas.clipPath来实现,适用于任何View(无法去除锯齿效果) package com.bu_ish.blog; import ...
- ARM GNU 常用汇编伪指令介绍
abort .abort: 停止汇编 .align absexpr1, absexpr2: 以某种对齐方式,在未使用的存储区域填充值. 第一个值表示对齐方式,4, 8,16 或 32. 第 二个表 ...
- scala 中List的简单使用
/** * scala 中List的使用 * */ object ListUse { def main(args: Array[String]): Unit = { def decorator(l:L ...
- 深入解读阿里云数据库POLARDB核心功能会话读一致性
POLARDB架构 我们知道,POLARDB是一个由多个节点构成的数据库集群,一个主节点,多个读节点.对外默认提供两个地址,一个是集群地址,一个是主地址,推荐使用集群地址,因为它具备读写分离功能可以把 ...
- 免费带你体验阿里巴巴旗舰大数据计算产品MaxCompute
什么是MaxCompute? 众所周知,MaxCompute是阿里云推出的承载EB级的数据存储能力,百PB级的单日计算能力,公共云覆盖国内外十几个国家和地区,专有云包含城市大脑在内部署超过100+套的 ...
- thinkphp 使用函数
我们往往需要对模板输出变量使用函数,可以使用: 大理石平台支架 {$data.name|md5} 编译后的结果是: <?php echo (md5($data['name'])); ?> ...
- thinkphp 变量输出
在模板中输出变量的方法很简单,例如,在控制器中我们给模板变量赋值: 大理石平台支架 $name = 'ThinkPHP'; $this->assign('name',$name); $this- ...
- 8 包含min函数的栈
0 引言 题目:定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的min函数.在该栈中,调用min.push及pop的时间复杂度都是O(). 1 抽象问题具体化 2 具体问题抽象分析 需要解 ...