Why use fragment?
针对这个问题,在网上搜索了下,有以下一些看法: 1、fragments are more reusable than custom views. 作者认为,fragment能够封装单靠view无法处理的事。自定义控件无法处理跨activity交互等事件,还是需要靠activity来完成,这会增加custom views 和activity的耦合。不利于复用。而fragment可以封装更多的东西,包括AsyncTask,file and database access等。 2、the main reason to use Fragments are for the backstack and lifecyclefeatures. Otherwise, custom views are more light weight, simpler toimplement, and have the advantage that they can be nested.see here 主要原因是fragment提供了backstack支持界面状态的回退,以及生命周期特性。(在SDK...
android camera 摄像头预览画面变形
问题:最近在处理一下camera的问题,发现在竖屏时预览图像会变形,而横屏时正常。但有的手机则是横竖屏都会变形。 结果:解决了预览变形的问题,同时支持前后摄像头,预览无变形,拍照生成的jpg照片方向正确。 环境 : android studio, xiaomi m1s android4.2 miui v5 过程: 1. 预览 preview画面变形以sdk中apidemos里的camera为例,进行修改。先重现下问题,在AndroidManifest.xml中指定了activity 的screenOrientation为landspace,则预览正常。若指定为portrait,则图像会有拉伸变形。 找到正确的previewsize继续看demo代码,mCamera.getParameters().getSupportedPreviewSizes() 可以返回当前设备支持的一组previewSize,例如: 1920x1088 1280x720 800x480 768x432 720x480 640x480 576x432 480x320384x288 352x288...