SDK編寫模式采用ABtesting方案
1.每個庫的使用都是采用重定義樣式,更改XML配置即可,若你還是需要變動代碼,那就說明你的使用方式有誤。
如有3個功能,【拍照上傳原圖,拍照上傳頭像,拍照上傳4:3截圖,拍照上傳不規則截圖】,隻需要配置不同的樣式即可。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 重寫樣式,不開啟裁剪 -->
<style name="MyDivPhotoGraph" parent="@style/DivPhotoGraph">
<item name="graph_iscrop">false</item>
</style>
<!-- 重寫樣式,裁剪比率為1:1正方形 -->
<style name="MyDivPhotoGraph" parent="@style/DivPhotoGraph">
<item name="graph_clip_width">1</item>
<item name="graph_clip_height">1</item>
</style>
<!-- 重寫樣式,裁剪比率為4:3長方形 -->
<style name="MyDivPhotoGraph" parent="@style/DivPhotoGraph">
<item name="graph_clip_width">4</item>
<item name="graph_clip_height">3</item>
</style>
<!-- 重寫樣式,不按比例裁剪 -->
<style name="MyDivPhotoGraph" parent="@style/DivPhotoGraph">
<item name="graph_auto_scale">false</item>
</style>
</resources>
2.肌肉記憶模式。建議先基于SDK庫,建立多個test_xxx_styles.xml配置。在具體項目使用中,直接複制過去。
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIyVGduV2QvwVe0lmdhJ3ZvwFM38CXlZHbvN3cpR2Lc1TPB10QGtWUCpEMJ9CXsxWam9CXwADNvwVZ6l2c052bm9CXUJDT1wkNhVzLcRnbvZ2LcZXUYpVd1kmYr50MZV3YyI2cKJDT29GRjBjUIF2LcRHelR3LcJzLctmch1mclRXY39zM4EjN0YTN2ETMxETM1EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
3.View庫的使用,隻要在XML更改下引用路徑,并且在目标項目代碼引用中,并不需要引用到依賴庫的路徑。當然你要引用引用依賴庫的路徑也是可以的,隻是這種方式不推薦。引用在實際的項目中,産品會不斷讓你更改界面布局之類。這樣做的目的是為了,隻需要一句話更改布局,代碼不動,快速滿足産品更改需求。
/**隻需要再布局中更改引用路徑*/
<General.View.BlurImageView
android:id="@+id/img0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:src="@drawable/heng" />
/**在代碼中還是維持android的imageview引用*/
import android.widget.ImageView;
4.若想更改依賴庫的界面,請把依賴庫layout下的xml布局檔案,複制到目标項目的layout。在保持ID不變的情況下,可任意排版。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFffffff"
android:orientation="vertical" >
<SurfaceView
android:id="@id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!--更改浏覽器的布局,保持id名稱不變即可-->
<General.View.WebView
android:id="@id/webview"
style="@style/MyDivWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
5.若想更改某個依賴庫的一個圖檔,隻需要把依賴庫需要改變的圖檔,複制到目标項目,在保持檔案名稱一緻的情況下更改。如微信分享圖示umeng_div_weixin.png
更改為