Android中HorizontalScrollView的使用
由于移动设备物理显示空间一般有限,不可能一次性的把所有要显示的内容都显示在屏幕上。所以各大平台一般会提供一些可滚动的视图来向用户展示数据。Android平台框架中为我们提供了诸如ListView、GirdView、ScrollView等滚动视图控件,这几个视图控件也是我们平常使用最多的。我下面介绍一下HorizontalScrollView的使用和需要注意的点
LinearLayout
。TextView也是一个可滚动的视图控件,所以一般不需要HorizontalScrollView
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout. activity_main);mLinearLayout = (LinearLayout) findViewById(R.id.mygallery);File externalDir = Environment. getExternalStorageDirectory();String photosPath = externalDir.getAbsolutePath() + "/test/";File photosFile = new File(photosPath);for (File photoFile : photosFile.listFiles()) {mLinearLayout.addView(getImageView(photoFile.getAbsolutePath()));}}private View getImageView(String absolutePath) {Bitmap bitmap = decodeBitmapFromFile(absolutePath, 200, 200);LinearLayout layout = new LinearLayout(getApplicationContext());layout.setLayoutParams( new LayoutParams(250, 250));layout.setGravity(Gravity. CENTER);ImageView imageView = new ImageView(this);imageView.setLayoutParams( new LayoutParams(200,200));imageView.setScaleType(ImageView.ScaleType. CENTER_CROP);imageView.setImageBitmap(bitmap);layout.addView(imageView);return layout;}private Bitmap decodeBitmapFromFile(String absolutePath, int reqWidth, int reqHeight) {Bitmap bm = null;// First decode with inJustDecodeBounds=true to check dimensionsfinal BitmapFactory.Options options = new BitmapFactory.Options();options. inJustDecodeBounds = true ;BitmapFactory. decodeFile(absolutePath, options);// Calculate inSampleSizeoptions. inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);// Decode bitmap with inSampleSize setoptions. inJustDecodeBounds = false ;bm = BitmapFactory. decodeFile(absolutePath, options);return bm; }private int calculateInSampleSize(Options options, int reqWidth,int reqHeight) {// Raw height and width of imagefinal int height = options.outHeight;final int width = options.outWidth;int inSampleSize = 1;if (height > reqHeight || width > reqWidth) {if (width > height) {inSampleSize = Math. round((float)height / ( float)reqHeight); } else {inSampleSize = Math. round((float)width / ( float)reqWidth); } }return inSampleSize; }
new Handler().postDelayed(new Runnable() {@Overridepublic void run() {// 水平直接滚动800px,如果想效果更平滑可以使用smoothScrollTo(int x, int y)hsv.scrollTo(800, 0);}}, 2000);
效果大致如下
Android中HorizontalScrollView的使用相关推荐
- Android中HorizontalScrollView的使用总结
HorizontalScrollView是Google推出的用来滚动查看视图的控件,已经替代了Gallery. 由于HorizontalScrollView继承自FrameLayout,这意味着你只能 ...
- Android中Touch事件分析--解决HorizontalScrollView滑动和按钮事件触发问题
1).按下按钮,不滑动,触发按钮功能 (2).按下按钮,滑动触发滑动事件 这里的按下包含长按和短按情况 首先要解决这个问题需要明白Android中的Touch事件是如何进行处理的,这里有一篇文章:An ...
- android 侧滑删除功能,200行代码让你在Android中完美实现iOS版侧滑删除效果
使用几个月的IOS之后,发现IOS中侧滑删除俺就 大家好,自己开始学习Android已经差不多半年了吧,前前后后看了不少的博客获益匪浅.渐渐的随着技术的提升,慢慢感觉网上其它的一些功能的实现又不是那么 ...
- android中view手势滑动冲突的两种解决方法
android中view手势滑动冲突的解决方法,主要解决方法有两种,外部和内部拦截.有需要的可以参考下. Android手势事件的冲突跟点击事件的分发过程息息相关,由三个重要的方法来共同完成,分别是: ...
- Android 用HorizontalScrollView实现ListView的Item滑动删除
原理: 利用HorizontalScrollView可以横向滚动的特点实现滑动,根据动态的设置要展示的区域宽度,使得其余选项操作被挤出屏幕外面,从而实现单条滑动菜单的样式. 实现步骤: 实现Listv ...
- Android 用HorizontalScrollView实现ListView的Item滑动删除 ,滑动错乱 冲突
用HorizontalScrollView实现类似微信的滑动删除 测试于:Android2.2+ 对于Android来说按键操作已经在减少,越来越多的手势操作层出不穷,今天介绍一款LIstView的I ...
- Android 自定义 HorizontalScrollView 横向滑动效果
自从Gallery被谷歌废弃以后,Google推荐使用ViewPager和HorizontalScrollView来实现Gallery的效果.的确HorizontalScrollView可以实现Gal ...
- android设计轮播功能按钮,Android TV HorizontalScrollView 图片轮播 遥控器上下按键的处理...
当前位置:我的异常网» Android » Android TV HorizontalScrollView 图片轮播 遥控器 Android TV HorizontalScrollView 图片轮播 ...
- [Android]使用HorizontalScrollView实现广告栏Banner及相关原理分析
现在的App中,广告栏Banner的使用还是挺广泛的,用于展示各种广告.活动推荐等.使用HorizontalScrollView可以很简单的实现一个可自动播放.可滑动.可点击的广告栏Banner,这个 ...
最新文章
- class没有发布到tomcat_基于Tomcat的Websocket范例及permessage-deflate扩展特性的研究
- vscode输入vue自动_vscode配置总结可收藏/vscode用户设置大全/vue代码模板,vscodevue...
- 用redis解决超卖
- 大工19春计算机文化基础在线测试1,大工19春《计算机文化基础》在线测试1(含答案)...
- 新修订未成年人保护法6月1日正式实施
- Qt学习之路1---软件下载安装及工程简介
- grunt入门讲解4:如何创建task(任务)
- yasm linux gcc,vs+msys2+yasm 编译libx264+ffmpeg详细解释(32位或64位)
- 【目标检测】Receptive Field Block Net for Accurate and Fast Object Detection论文理解
- PowerPoint PPT 模板插入可修改的文本框
- vulfocus——骑士cms任意代码执行(CVE-2020-35339)
- python 解决问题的集合-No JSON object could be decoded
- 网络号,IP,子网掩码之间的关系
- 戴尔服务器r510怎么系统,DELLR510服务器上安系统.docx
- 网易云--手机QQ的换肤是怎么做到的,你对换肤有了解吗?看过换肤的原理没?
- Linux命令学习笔记(一)目录操作
- 桌宠必须要java吗_桌宠软件电脑版下载_桌面宠物软件免费版下载_3DM软件
- jupyter–lab 配置文件jupyter_lab_config.py
- 使用安卓(华为)手机通过USB共享网络至Mac (M1pro)
- 入坑nodemcu,从刷固件到点亮LED,读完这篇文章就够了
热门文章
- 618主场之变:谁是后疫情时代消费的主角?
- win10可用空间变成未分配_有关如何在win10系统中对未分配的磁盘空间进行分区的详细教程...
- 遍历HashMap的几种方法
- js用正则表达式完成邮箱验证
- 面试中的老大难 - MySQL中的锁
- Single Scale Retinex 增强 matlab 实现
- pyqt5按钮拖拽,实现拖拽新增和拖拽移动
- 机器学习_深度学习毕设题目汇总——人脸B
- 如何在linux的gcc中添加c语言的外部链接库(“比如说,math.h
- 你应该使用什么语言开发App?