2009年10月19日 星期一

善用?android:attr,而非直接指定顏色或字形大小

良:
<Button
android:id="@+id/rating_OK" android:layout_width="wrap_content"        android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/ok"
/>

不良:
<Button
android:id="@+id/rating_OK" android:layout_width="wrap_content"        android:layout_height="wrap_content"
android:textSize="24px"
android:text="@string/ok"
/>

原因很簡單,因為在不同的螢幕大小上Android會自行調整這些Attr的實際數據,所以你就不用改這些xml檔。但是如果你自行指定,就準備對應一個螢幕就要改一次……

沒有留言:

張貼留言