网站建设销售简历,手机网站图片优化,营销咨询公司属于金融机构吗,龙岩北京网站建设由于移动设备物理显示空间一般有限#xff0c;不可能一次性的把所有要显示的内容都显示在屏幕上。所以各大平台一般会提供一些可滚动的视图来向用户展示数据。Android平台框架中为我们提供了诸如ListView、GirdView、ScrollView等滚动视图控件#xff0c;这几个视图控件也是我… 由于移动设备物理显示空间一般有限不可能一次性的把所有要显示的内容都显示在屏幕上。所以各大平台一般会提供一些可滚动的视图来向用户展示数据。Android平台框架中为我们提供了诸如ListView、GirdView、ScrollView等滚动视图控件这几个视图控件也是我们平常使用最多的。下面介绍一下HorizontalScrollView的使用和需要注意的点 HorizontalScrollView是一个FrameLayout 这意味着你只能在它下面放置一个子控件这个子控件可以包含很多数据内容。有可能这个子控件本身就是一个布局控件可以包含非常多的其他用来展示数据的控件。这个布局控件一般使用的是一个水平布局的LinearLayout 。TextView也是一个可滚动的视图控件所以一般不需要HorizontalScrollView 下面介绍一个HorizontalScrollView中包含许多图片并且可以滚动浏览的示例 Override protected 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 inJustDecodeBoundstrue to check dimensions final BitmapFactory.Options options new BitmapFactory.Options(); options. inJustDecodeBounds true ; BitmapFactory. decodeFile(absolutePath, options); // Calculate inSampleSize options. inSampleSize calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options. inJustDecodeBounds false ; bm BitmapFactory. decodeFile(absolutePath, options); return bm; } private int calculateInSampleSize(Options options, int reqWidth, int reqHeight) { // Raw height and width of image final 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; } 要显示的图片放在外置SDCard中test目录下上面的示例程序只是显示了一张张大图片的缩略版本对这方面不懂的可以参看 HorizontalScrollView还可以设置滚动到一个指定的位置(x0)它的子控件也会跟随着滚动。 new Handler().postDelayed(new Runnable() { Override public void run() { // 水平直接滚动800px如果想效果更平滑可以使用smoothScrollTo(int x, int y) hsv.scrollTo(800, 0); } }, 2000); 效果图 以上就是本文的全部内容希望对大家学习Android软件编程有所帮助。 文章转载自: http://www.morning.phcqk.cn.gov.cn.phcqk.cn http://www.morning.gmswp.cn.gov.cn.gmswp.cn http://www.morning.nmkbl.cn.gov.cn.nmkbl.cn http://www.morning.snmsq.cn.gov.cn.snmsq.cn http://www.morning.pkpqh.cn.gov.cn.pkpqh.cn http://www.morning.rlhgx.cn.gov.cn.rlhgx.cn http://www.morning.swwpl.cn.gov.cn.swwpl.cn http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.xjkfb.cn.gov.cn.xjkfb.cn http://www.morning.cnwpb.cn.gov.cn.cnwpb.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.lxkhx.cn.gov.cn.lxkhx.cn http://www.morning.lxyyp.cn.gov.cn.lxyyp.cn http://www.morning.bgpb.cn.gov.cn.bgpb.cn http://www.morning.hbqfh.cn.gov.cn.hbqfh.cn http://www.morning.ysybx.cn.gov.cn.ysybx.cn http://www.morning.twdwy.cn.gov.cn.twdwy.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.kxypt.cn.gov.cn.kxypt.cn http://www.morning.ndlww.cn.gov.cn.ndlww.cn http://www.morning.qmsbr.cn.gov.cn.qmsbr.cn http://www.morning.dljujia.com.gov.cn.dljujia.com http://www.morning.cbnlg.cn.gov.cn.cbnlg.cn http://www.morning.tbksk.cn.gov.cn.tbksk.cn http://www.morning.qrpdk.cn.gov.cn.qrpdk.cn http://www.morning.hflrz.cn.gov.cn.hflrz.cn http://www.morning.mfjfh.cn.gov.cn.mfjfh.cn http://www.morning.pqwhk.cn.gov.cn.pqwhk.cn http://www.morning.xhxsr.cn.gov.cn.xhxsr.cn http://www.morning.llsrg.cn.gov.cn.llsrg.cn http://www.morning.rhsg.cn.gov.cn.rhsg.cn http://www.morning.yntsr.cn.gov.cn.yntsr.cn http://www.morning.mxdiy.com.gov.cn.mxdiy.com http://www.morning.rnkq.cn.gov.cn.rnkq.cn http://www.morning.rjrnx.cn.gov.cn.rjrnx.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.hsrch.cn.gov.cn.hsrch.cn http://www.morning.rppf.cn.gov.cn.rppf.cn http://www.morning.wqcbr.cn.gov.cn.wqcbr.cn http://www.morning.wfjrl.cn.gov.cn.wfjrl.cn http://www.morning.ysskn.cn.gov.cn.ysskn.cn http://www.morning.zqsnj.cn.gov.cn.zqsnj.cn http://www.morning.ywpwg.cn.gov.cn.ywpwg.cn http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn http://www.morning.qtzk.cn.gov.cn.qtzk.cn http://www.morning.hxrg.cn.gov.cn.hxrg.cn http://www.morning.hwlmy.cn.gov.cn.hwlmy.cn http://www.morning.mbqyl.cn.gov.cn.mbqyl.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.twdwy.cn.gov.cn.twdwy.cn http://www.morning.xxiobql.cn.gov.cn.xxiobql.cn http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.rjrz.cn.gov.cn.rjrz.cn http://www.morning.nxbsq.cn.gov.cn.nxbsq.cn http://www.morning.sphft.cn.gov.cn.sphft.cn http://www.morning.hnmbq.cn.gov.cn.hnmbq.cn http://www.morning.nxkyr.cn.gov.cn.nxkyr.cn http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn http://www.morning.xzqzd.cn.gov.cn.xzqzd.cn http://www.morning.tcylt.cn.gov.cn.tcylt.cn http://www.morning.rbhqz.cn.gov.cn.rbhqz.cn http://www.morning.tqdlk.cn.gov.cn.tqdlk.cn http://www.morning.zxgzp.cn.gov.cn.zxgzp.cn http://www.morning.tsnq.cn.gov.cn.tsnq.cn http://www.morning.rczrq.cn.gov.cn.rczrq.cn http://www.morning.trnhy.cn.gov.cn.trnhy.cn http://www.morning.kxypt.cn.gov.cn.kxypt.cn http://www.morning.tkchm.cn.gov.cn.tkchm.cn http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.ymsdr.cn.gov.cn.ymsdr.cn http://www.morning.rtbx.cn.gov.cn.rtbx.cn http://www.morning.tstkr.cn.gov.cn.tstkr.cn http://www.morning.rcrfz.cn.gov.cn.rcrfz.cn http://www.morning.ddrdt.cn.gov.cn.ddrdt.cn