收藏夹Android高级开发面试题面试汇总

Android面试大全(性能优化篇)

2017-03-10  本文已影响2297人  fengcz

Android面试大全(四大组件篇)
Android面试大全(性能优化篇)
Android面试大全(异常处理篇)
Android面试大全(开源框架篇)
Android面试大全(网络篇)
Android面试大全(java篇)


前言

android中的性能优化这一方面不止是一道面试题,也是项目中必须要做的一件事情,只有做好的性能方面的优化,用户体验满意度才会有所提升

分类

启动黑白屏问题

  <style name="Mytheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@mipmap/ic_launcher</item>//设置图片
        <item name="ndroid:windowBackground">@color/fireBar</item>//设置纯色
        <item name="android:windowNoTitle">true</item>//去title
    </style>

布局优化

图片的优化

android中图片的使用是非常占用内存资源的。

/**创建缩略图方法
*filepath 图片路径
 i  压缩比例,最终为原图的1/(i^2)
*/
 private Bitmap onCreateThumbnail(String filePath, int i) {
         BitmapFactory.Options options=new BitmapFactory.Options();
        //设置为不读内容,值读取边界值
          options.inJustDecodeBounds=true;
         //通过编辑,得到边界值,并存入到option中
         BitmapFactory.decodeFile(filePath,options);
        //赋值缩放比例
         options.inSampleSize=i;
         //设置显示的图片格式
         options.inPreferredConfig=Config.RGB_565;
         //设置为读取内容,
         options.inJustDecodeBounds=false;
        //得到缩略图
         return BitmapFactory.decodeFile(filePath2, options);
     }
final Button button=new Button(this);
        button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        //手指按下
                        button.setBackgroundResource(R.mipmap.down);
                        break;
                    case MotionEvent.ACTION_UP:
                        //手指抬起,恢复
                        button.setBackgroundResource(R.mipmap.up);
                        break;
                }
                //为了监听事件的分发,返回false
                return false;
            }
        });

大量数据优化

列表项优化

其他优化


正在持续跟新中……

上一篇 下一篇

猜你喜欢

热点阅读