Android之樣式化
阿新 • • 發佈:2018-12-11
佈局程式碼為
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/black" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!--應用樣式1的TextView--> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/DavidStyleText1" android:gravity="center_vertical|center_horizontal" android:text="應用DavidStyleText1樣式的"/> <!--應用樣式2的TextView--> <TextView style="@style/DavidStyleText2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal|center_vertical" android:text="應用於DavidStyleText2樣式的"/> </LinearLayout>
1.LinearLayout線性佈局,從頭到尾,要跟上android:orientation表示橫著還是豎著 2.android:gravity抽象對應重力,"center_vertical|center_horizonta既往豎直中間偏,又往水平中間偏 style中程式碼為
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="DavidStyleText1"> <item name="android:textSize">18sp</item> <item name="android:textColor">#EC9237</item> </style> <style name="DavidStyleText2"> <item name="android:textSize">14sp</item> <item name="android:textColor">#FF7F7C</item> <item name="android:fromAlpha">0.0</item> <item name="android:toAlpha">0.0</item> </style> </resources>
1.fromAlpha toAlpha起始透明度與結束透明度