標籤:android c style class blog code
1.父控制項中含有多個子控制項時,往往遵循長子優先的原則,即長子如果很大可能佔滿父空間,使次子們出局;
2.假設TableLayout有2行,其中一行未設定列間長度比例,而另一行設定了,則未設定行可能也會遵循設定行的列間長度比例;
3.在某個地區(如TableLayout中某個單元格)顯示某張超大的圖片,希望圖片總是自適應單元格而不是把單元格撐爆。解決方案:將單元格放在LinearLayout中,給LinearLayout設定android:layout_width="wrap_content"、android:orientation="horizontal",給單元格設定layout_weight屬性、不設定android:layout_width屬性。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff"> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/include1" android:background="#dedcd2" android:stretchColumns="*" > <TableRow android:layout_margin="0.5dip" android:background="#dedcd2" > <LinearLayout android:layout_width="wrap_content" android:layout_height="30dp" android:orientation="horizontal" > <TextView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="2" android:background="#ffffff" android:text="" android:textSize="12dp" android:textStyle="bold" /> <TextView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="2" android:background="#ffffff" android:text="" android:textSize="12dp" android:textStyle="bold" /> <!-- @drawable/right 為超大圖片 --> <ImageView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="1" android:src="@drawable/right" /> <TextView android:layout_height="fill_parent" android:layout_margin="1dip" android:layout_weight="2" android:background="#ffffff" android:text="" android:textSize="12dp" android:textStyle="bold" /> </LinearLayout> </TableRow> </TableLayout></RelativeLayout>