美文网首页
Android优化

Android优化

作者: 读书人heart | 来源:发表于2019-08-14 16:39 被阅读0次

    解决RecyclerView更新闪一下
    ((DefaultItemAnimator)rvGoodCoupon.getItemAnimator()).setSupportsChangeAnimations(false);
    不行再加这个
    adapter.setHasStableIds(true);
    recyclerview数据错乱
    重写getItemViewType

                           @Override
                            public int getItemViewType(int position) {
                                return position;
                            }
    

    https://www.pgyer.com/uMso
    多功能刷新库
    https://github.com/scwang90/SmartRefreshLayout

    Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use .override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions.

    RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL);
            Glide.with(context).load(path).apply(options).into(new SimpleTarget<Drawable>() {
                @Override
                public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                    imageView.setImageDrawable(resource);
                }
            });
    

    //会导致图片顺序错乱
    imageAdapter.setHasStableIds(true);

    android 10 shape 默认渐变方向 从左到右 变成了 从上到下

    android 10 从后台返回前台,在onRestart无法立即拿到剪贴版的内容会拿到空,必须延迟1秒后在调用

    android 10 出现选择图片,图片都是灰色 在AndroidManifest.xml添加 android:requestLegacyExternalStorage="true"

    极光通知没有声音(自己在收到通知的地方播放声音和震动)

    import android.content.Context;
    import android.content.res.AssetFileDescriptor;
    import android.content.res.AssetManager;
    import android.media.MediaPlayer;
    import android.os.Vibrator;
    
    import java.io.IOException;
    
    import static com.xuexiang.xutil.resource.ResUtils.getResources;
    
    class CommUtil {
        /**
         * 播放声音
         */
        public static void play(){
            AssetManager assetManager;
            MediaPlayer player = null;
            player = new MediaPlayer();
            assetManager = getResources().getAssets();
            try {
                AssetFileDescriptor fileDescriptor = assetManager.openFd("tip.mp3");
                player.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getStartOffset());
                player.prepare();
                player.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        /**
         * 震动
         * @param duration  毫秒
         * @param mContext
         */
        public static  void shakePhone(int duration, Context mContext)
        {
          //  需要添加权限   <uses-permission android:name="android.permission.VIBRATE"/>
            Vibrator mVibrator = (Vibrator)mContext.getSystemService(Context.VIBRATOR_SERVICE);
            mVibrator.vibrate(duration);
        }
    }
    
    

    相关文章

      网友评论

          本文标题:Android优化

          本文链接:https://www.haomeiwen.com/subject/vshfjctx.html