開發總結1:,開發總結1
項目UI總結
今天整理了一天的項目UI,為了更接近當初的原型設計和UI美工這邊給我的。進行了一天的項目重構和代碼最佳化。
類似於更多的列表item
通常我們在開發中,常用的是提取一個通用的item 作為一個模板,然後使用adapter,進行資料適配。如果這僅僅是一個固定數目的列表。我們可能會使用線性布局LinearLayout,然後放置若干條子布局,此時,有一個問題出來了,如果,有很多個這種布局相同的菜單出現在這個App中,這時,還能像我這樣寫但一個一個item代碼嗎?
<LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:background="#ffebe6" android:gravity="center" android:visibility="gone" android:id="@+id/position_bar" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="center" android:drawableLeft="@drawable/tips_icon" android:drawablePadding="8dp" android:gravity="center" android:text="保證金不足,請及時追加" android:textColor="#333333" android:textSize="12sp" /> </LinearLayout>
如果項目中僅有兩三處這麼寫,或許還無可厚非,如果我這裡的列表在 A Activity 中有8 個,B Activity 中有 8個或者其他中還有更多,那麼這個時候,就應該思考是否要重構你的代碼了。這時android 中 的Style 就應該考慮讓它出場了。於是我用Android studio 的自動extract 功能重構了一個Style ,並讓IDE幫我替換全工程中這種大量的複用代碼 。
<style name="position_tile_item"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:drawableLeft">@drawable/red_dot</item> <item name="android:drawablePadding">3dp</item> <item name="android:textSize">12sp</item> <item name="android:textColor">#333333</item> <item name="android:textAppearance">?android:attr/textAppearanceSmall</item> </style>
這是我IDE幫我重構的一個Style之後,我在後面需要用的部分,全部直接引用Style即可。
後面My Code就變的更加精簡。如下
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="15dp" android:layout_weight="1" android:gravity="center_vertical" android:orientation="horizontal"> <TextView style="@style/position_tile_item" android:text="份額:" /> <TextView style="@style/positin_title2_style" android:text="9891315.65" /> <TextView style="@style/position_title3_item" android:text="元" /> </LinearLayout>
或許,看到這裡,其實,這篇文章,並沒有講述一個什麼高深方法。
這篇文章的目的:
- 整理我的日常項目總結,學習筆記。
- 發布筆記,我的技術感想
- 撰寫發布一下學習心得
- 為自己平時自己伸手黨開始悔改,為開源貢獻自己的一點力量。
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。