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檔。但是如果你自行指定,就準備對應一個螢幕就要改一次……

沒有留言:

CODE { display: block; /* fixes a strange ie margin bug */ font-family: Courier New; font-size: 8pt; overflow:auto; background: #f0f0f0 url(http://klcintw.images.googlepages.com/Code_BG.gif) left top repeat-y; border: 1px solid #ccc; padding: 10px 10px 10px 21px; max-height:200px; height:200px; // for IE6 line-height: 1.2em; } #quote { display: block; /* fixes a strange ie margin bug */ font-family: Verdana; font-size: 10pt; overflow:auto; background: #f7f7f7 url(http://lh5.ggpht.com/_z-VThISftkI/SXUlpyfw9ZI/AAAAAAAABYY/e3GUx9_Z4TE/s288/quote-l.gif) left top no-repeat; border: 4px dotted #ccc; padding: 15px 15px 15px 31px; /*up right bottom left*/ max-height:300px; line-height: 1.2em; }