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 ...
随机推荐
- 常用sign算法
所有参数包括appkey或者token拼接成&key=value格式 转小写 正序排序 MD5后得到sign
- 将excel表格或csv转换为Shapefile文件
读取csv转为shp 构造读取csv函数 def read_csv(fp): ret = [] with open(fp, 'rb') as f: for line in f: ret.append( ...
- LightOJ 1245 - Harmonic Number (II)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:仿照上面那题他想求这么个公式的数.但是递归太慢啦.让你找公式咯. ...
- 基于NEO4J的高级检索功能
基于NEO4J的高级检索 一.需求 二.创建索引 1.索引自动更新配置 2.执行带有索引自动更新配置的过程 三.查询索引 1.LUCENE查询语法 2.实现高级检索的核心:LUCENE QUERY语句 ...
- static/extern&const个人理解
//const仅仅用来修饰右边的变量(基本数据变量p,指针变量*p) static NSString *const keyA = @"keyA"; static NSString ...
- Ubuntu18.04安装RTX2080Ti+NVIDIA驱动+CUDA
Ubuntu18.04安装RTX 2080Ti 与 Cuda10 ==========血泪更新========= 如果可以使用ppa安装最方便了 具体参考:https://www.cnblogs.co ...
- xx市xx项目运维工作方案
注:提供给各位正在做项目,或准备做项目的朋友,仅供参考,用于后期运维提供的方案模板.仅供参考. 因为直接从word复制,会有一些排版的问题.可以留邮箱. xx市xx项目运维工作方案 xx有限公司 20 ...
- QQ空间批量删除说说
按下F12,贴下如下代码 var delay = 1000; function del() { if (document.querySelector(".app_canvas_frame&q ...
- TopCoder[SRM513 DIV 1]:Reflections(1000)
Problem Statement Manao is playing a new game called Reflections. The goal of the game is trans ...
- kubernetes忘记token或者token过期怎么加入k8s集群
1.先查看token是否还可用 [root@hadoop01 ~]# kubeadm token list 1.1) 还在则获取ca证书sha256编码hash值,不在则进行2操作 openssl x ...