Android 学习笔记(7)——ScrollView(竖直滚动条)/HorizontalScrollView(水平滚动条)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android 学习笔记(7)——ScrollView(竖直滚动条)/HorizontalScrollView(水平滚动条),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4476字,纯文字阅读大概需要7分钟。
内容图文
作者:夏至 欢迎转载,也请保留这段申明,谢谢
<? xml version = "1.0" encoding = "utf-8" ?>
< ScrollView xmlns : android = "http://schemas.android.com/apk/res/android"
android : layout_width = "match_parent"
android : layout_height = "match_parent"
android : id = "@+id/scrollView" >
< LinearLayout
android : layout_width = "match_parent"
android : layout_height = "match_parent"
android : orientation = "vertical" >
< Button
android : id = "@+id/bottom"
android : layout_width = "match_parent"
android : layout_height = "wrap_content"
android : textSize = "24sp"
android : text = "跳到底部"
/>
< TextView
android : layout_width = "match_parent"
android : layout_height = "wrap_content"
android : text = "实现翻滚效果"
android : textSize = "24sp"
/>
< ImageView
android : layout_width = "wrap_content"
android : layout_height = "wrap_content"
android : src = "@drawable/image1"
/>
< ImageView
android : layout_width = "wrap_content"
android : layout_height = "wrap_content"
android : scaleType = "fitCenter"
android : src = "@drawable/image2"
/>
< ImageView
android : layout_width = "wrap_content"
android : layout_height = "wrap_content"
android : scaleType = "fitCenter"
android : src = "@drawable/shaorui"
/>
< ImageView
android : layout_width = "wrap_content"
android : layout_height = "wrap_content"
android : scaleType = "fitCenter"
android : src = "@drawable/start"
/>
< ImageView
android : layout_width = "wrap_content"
android : layout_height = "wrap_content"
android : scaleType = "fitCenter"
android : src = "@drawable/stop"
/>
< Button
android : id = "@+id/top"
android : layout_width = "match_parent"
android : layout_height = "wrap_content"
android : textSize = "24sp"
android : text = "回到顶部"
/>
</ LinearLayout >
</ ScrollView >
public class MainActivity extends AppCompatActivity implements View . OnClickListener {
private ScrollView scrollView ;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . linearlayout );
Button top = ( Button ) findViewById ( R . id . top );
Button bottom = ( Button ) findViewById ( R . id . bottom );
scrollView = ( ScrollView ) findViewById ( R . id . scrollView );
top . setOnClickListener ( this );
bottom . setOnClickListener ( this );
}
@Override
public void onClick ( View v ) {
switch ( v . getId ()) {
case R . id . top :
scrollView . fullScroll ( ScrollView . FOCUS_UP );
break ;
case R . id . bottom :
scrollView . fullScroll ( ScrollView . FOCUS_DOWN );
break ;
}
}
< HorizontalScrollView
xmlns : android = "http://schemas.android.com/apk/res/android"
android : layout_width = "match_parent"
android : layout_height = "wrap_content"
android : id = "@+id/scrollView" >
< LinearLayout
- android : layout_width = "match_parent"
android : layout_height = "match_parent"
android : orientation = "horizontal" >
.....
public class MainActivity extends AppCompatActivity implements View . OnClickListener {
private HorizontalScrollView horizontalScrollView ;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . linearlayout );
Button top = ( Button ) findViewById ( R . id . top );
Button bottom = ( Button ) findViewById ( R . id . bottom );
horizontalScrollView = ( HorizontalScrollView ) findViewById ( R . id . scrollView );
top . setOnClickListener ( this );
bottom . setOnClickListener ( this );
}
@Override
public void onClick ( View v ) {
switch ( v . getId ()) {
case R . id . top :
horizontalScrollView . fullScroll ( HorizontalScrollView . FOCUS_UP );
break ;
case R . id . bottom :
horizontalScrollView . fullScroll ( HorizontalScrollView . FOCUS_DOWN );
break ;
}
}
原文:http://www.cnblogs.com/shaorui/p/5206597.html
内容总结
以上是互联网集市为您收集整理的Android 学习笔记(7)——ScrollView(竖直滚动条)/HorizontalScrollView(水平滚动条)全部内容,希望文章能够帮你解决Android 学习笔记(7)——ScrollView(竖直滚动条)/HorizontalScrollView(水平滚动条)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。