天天看点

Android路上踩到的坑ing

1. WebView不断的刷新导致内存不足,闪退

    问题:用WebView加载一个h5页面去抢购功能,不断点击右上角刷新按钮加载WebView闪退 

    解决方案:在WebView的onDestroy()里面移除WebView

     if (mWebview != null) { 

          ((ViewGroup) mWebview.getParent()).removeView(mWebview); 

          mWebview.removeAllViews(); 

          mWebview.destroy(); 

        } 

2. 系统的裁剪和图库以及拍照问题

   问题:

   1)调用系统的图库然后裁剪,在nexus 6.0的系统上会出现闪退

   2)调用系统图库,在小米4的手机上没办法回调裁剪功能

   3)调用系统图片在魅蓝Note上无法回调

   4)调用系统拍照在三星N7200上面回调回来Activity会重新创建

   解决方案:1)自己写图库和裁剪功能

             2)进行图片压缩,手机拍出来的照片一般3M左右

             3)三星N7200拍照屏幕会发生旋转,Activity的生命周期会全部重新执行一遍,

   在Mainfest.xml里面配置Activity的属性android:configChanges="orientation|keyboardHidden|screenSize"

3. 用RadioGroup的问题

   问题:

   1)RadioGroup里面的RadioButton用weight平分,在用gravity设置里面的文字居中时,在三星N7000等部分机        型上无法居中 

   2)RadioButton点击时有背景

   解决方案:1)设置RadioButton的android:paddingLeft="0dp" 

             2)设置android:background="@null"

4. Git在Pull或Push时遇到的问题

   问题:

   1)出现Unable to create 'XXX/.git/index.lock’: File exists

   解决方案:cmd命令行下进入项目的.git目录下,输入del index.lock删除该文件 <br><br>

   2)出现Merge failed Some untracked working tree files would be overwritten by merge. Please move or    remove them before you merge. <strong>View them</strong> 

   解决方案:本地的文件跟服务器冲突了,删除本地不属于自己或冲突的文件,在更新或添加,去目录里面找会有    颜色提示 

5. 微信分享或支付问题

   问题:微信分享无法调起微信或调起微信闪退,微信分享成功或取消分享回来页面卡住

   解决方案:1)检查微信秘钥和开发平台的秘钥是否相同,检查apk是否是同一个签名文件,比如申请appId用的是    debug模式签名,而在本地装的是release签名

             2)分享成功闪退,微信里面的参数(标题、内容、bitmap等)不能传null或空字符

             3)页面卡住是因为回调了WXEntryActivity类,重新开启了一个不可见的Activity,在回调回来的

onResp()里面finish掉      
6.图片View1平移缩放到一个指定的View2时有偏差      
问题:int[] location = new int[2];       
cartTv.getLocationInWindow(cartLocation2);这样得到的是目标View1左上点的坐标,从View1平移缩放到View2时是左上角的坐标点重合,因为缩放所以图片会偏右下方,没在View2的中心      
解决方案:View2的坐标这样重新计算中心点      
int[] location = new int[2];      
Rect rect = new Rect();      
cartTv.getGlobalVisibleRect(rect);      
location [0] = rect.left - View1.getWidth()      
- (rect.right - rect.left)) / 2;
location [1] = rect.top - View.getHeight()      
- (rect.bottom - rect.top)) / 2;
7.获取ImageView的Drawable赋值给另一个ImageView      
问题:因为是同一个对象,所以在另一个ImageView改变大小的时候前一个ImageView的大小也改变了      
解决方案:通过ImageView的缓存获取Bitmap对象赋值      
ImageView imageView = new ImageView(this);      
imageView.destroyDrawingCache();
  imageView.setDrawingCacheEnabled(true);
  imageView.measure(View.MeasureSpec.makeMeasureSpec((DensityUtils.getWindowWidth(activity)), View.Mea  sureSpec.EXACTLY), View.MeasureSpec.makeMeasu  reSpec((DensityUtils.getWindowWidth(activity)), View   .MeasureSpec.EXACTLY));
  imageView.layout(0, DensityUtils.dp2px(activity, 10), imageView.getMeasuredWidth(), imageView.getMe  asuredHeight() + DensityUtils.dp2px(activity, 10));
  imageView.buildDrawingCache();
  return imageView.getDrawingCache();