处理一些warning

1.Avoid object allocations during draw/layout operations (preallocate and reuse instead)

用Android自带的lint测试,发现上面这个问题。。。。百度一番发现。。。在ondraw/onlayout中尽量不要用new 对象的操作。。。因为ondraw/onlayout会经常被调用;这样比较耗内存。。。。

2.The vertically scrolling ScrollView should not contain another vertically scrolling widget (GridView)

3.Incorrect line ending: found carriage return (\r) without corresponding newline (\n)

4.This LinearLayout should use android:layout_height="wrap_content"

回答:ScrollView children must set their layout_width or layout_height attributes to wrap_content rather than fill_parent or match_parent in the scrolling dimension,ScrollView的子View必须设置他们的宽或者高为wrap_content.

5.The following images appear in both -nodpi and in a density folder: search_play_icon.png, search_ugc_icon_filter.png, volumn_bg.9.png, volumn_front.9.png, volumn_primary.9.png

回答:以下的图片在nodpi中Bitmaps that appear in drawable-nodpi folders will not be scaled by the Android framework. If a drawable resource of the same name appears both in a -nodpi folder as well as a dpi folder such as drawable-hdpi, then the behavior is ambiguous and probably not intentional. Delete one or the other, or use different names for the icons.删除nodpi中的图片,或者定义名字和其他资源包的名字不一样。。。

6.Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead

回答:不要硬编码。。而是要用系统的Environment.getExternalStorageDirectory().getPath()

7.Replace "-" with an "en dash" character (–, –) ?

回答:在string引用文件中把-替换成–

8.This Handler class should be static or leaks might occur 

回答:In Android, Handler classes should be static or leaks might occur. Messages enqueued on the application thread's MessageQueue also retain their target Handler. If the Handler is an inner class, its outer class will be retained as well. To avoid leaking the outer class, declare the Handler as a static nested class with a WeakReference to its outer class.

9.Use new SparseArray<ArrayList<TextView>>(...) instead for better performance

回答:当定义new HashMap<Integer, ArrayList<TextView>>();这个类型时,Android建议

For maps where the keys are of type integer, it's typically more efficient to use the Android SparseArray API. This check identifies scenarios where you might want to consider using SparseArray instead of HashMap for better performance.


This is particularly useful when the value types are primitives like ints, where you can use SparseIntArray and avoid auto-boxing the values from int to Integer.


If you need to construct a HashMap because you need to call an API outside of your control which requires a Map, you can suppress this warning using for example the @SuppressLint annotation.

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值