GeXiangDong

精通Java、SQL、Spring的拼写,擅长Linux、Windows的开关机

0%

避开Android警告'Nested weights are bad for performance'

Eclipse 提示Warning “Nested weights are bad for performance”

原因很简单:父子元素都使用了 android:weight=1属性。

最好的解决办法,不要嵌套使用android:weight属性。可以通过RelativeLayout布局替代LinearLayout布局来改善原有代码。 RelativeLayout的layout_toRightOf , layouttoLeftOf等一起用可以达到充满剩余空间的效果。

如果使用RelativeLayout仍旧无法达到效果,想不显示waring可以:

add to the root of your layout: xmlns:tools=”http://schemas.android.com/tools”. Then in your buttons add tools:ignore=”NestedWeights”

另外tools:ignore=”UselessParent”可以去掉提示两级元素多余(This LinearLayout layout or its FrameLayout parent is possibly useless; transfer the background attribute to the other view)的警告。

Reference: http://stackoverflow.com/questions/19636323/nested-weights-are-bad-for-performance-in-my-xml-code

使用SystemUiHider时,全屏的Layout必须加android:keepScreenOn=”true”属性,非全屏模式下的空间增加android:fitsSystemWindows=”true”不可颠倒,错误可能会出现非全屏模式下控件布局占用android占用系统虚拟键位置导致被遮挡的现象