Use a layout_width of 0dip instead of fill_parent for better performance
生活随笔
收集整理的這篇文章主要介紹了
Use a layout_width of 0dip instead of fill_parent for better performance
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝了最新的ATD 18之后,新加的Lint Warnings插件會給我們檢測出許多xml布局中不當的地方,例如:
Use a layout_width of 0dip instead of fill_parent for better performance
什么意思呢?舉個簡單的例子:
這是一個垂直布局,上下的線性布局各占高度50.0dp,中間的的TextView設置了android:layout_weight="1.0"屬性,會將剩余空間填充滿,這時候TextView的android:layout_width="fill_parent"就沒有用了,應該改為android:layout_width="0.0dp"。
我的理解:當設置了比重屬性后,在這個方向上的長度就不確定了,不需要再去適配任何屬性了,設置了也白設!因為控件都是繪制到屏幕上的,它會根據布局文件初始化控件在屏幕上的顯示,所以設置0dip就相當于初始化時不需要繪制了!
總結
以上是生活随笔為你收集整理的Use a layout_width of 0dip instead of fill_parent for better performance的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java.lang.ClassCastE
- 下一篇: QuickContact分析及其弹出窗口