仿迅雷之Android版-簡單說下粗糙的適配
由於介面的元素並不是很多,主要是彈窗,字型,位置,彈窗內的布局間距等那麼幾個,所以基本都是靠dimen來做的,同時稍微在產生彈窗布局的時候,通過代碼利用螢幕寬高,利用dimen的值來實現效果,基本還是可以滿足需求的;同樣:高手可以指點指點,或者飄過~~~
dimens.xml - 工程結構在http://blog.chinaunix.net/uid-25799257-id-4724749.html有描述
- <resources>
- <!-- Default screen margins, per the Android Design guidelines. -->
- <dimen name="activity_horizontal_margin">16dp</dimen>
- <dimen name="activity_vertical_margin">16dp</dimen>
- <dimen name="layout_menu_width">180dp</dimen>
- <dimen name="layout_menuItem_width">170dp</dimen>
- <dimen name="half_layout_menu_width">70dp</dimen>
- <dimen name="half_layout_menuIcon_width">50dp</dimen>
- <dimen name="layout_title_barItem_width">35.0dip</dimen>
- <dimen name="myAppPopuWinHeight">98.0dip</dimen>
- <dimen name="myAppPushDataShowTextVHeight">40.0dip</dimen>
- <dimen name="myAppPushDataShowTextVWidth">200.0dip</dimen>
- <dimen name="editSizeWidth">120.0dip</dimen>
- <dimen name="editSizeHeigth">40.0dip</dimen>
- <dimen name="private_tipTVMarginTop">100.0dip</dimen>
- <dimen name="private_tipTVMarginBottom">20.0dip</dimen>
- <dimen name="privatePassSureBtnWidth">80.0dip</dimen>
- <dimen name="privatePassSureBtnHeigth">60.0dip</dimen>
- <dimen name="privatePopuTiptextSize">10.0sp</dimen>
- <dimen name="textSize">18.0sp</dimen>
- </resources>
上面基本都是不同比例下,有一套這樣的檔案;有些直接在布局中使用,有些在代碼中使用,that is it.
比如(我的沒有的解析度會給出一個預設的9999dip);
- contentView = LayoutInflater.from(context).inflate(R.layout.myapppopuwin, null, true);
- ///< 擷取不同解析度下的我的App的彈窗的尺寸,並且如果沒有該尺寸,則設定為螢幕高度的1/4
- float popuWinHeight = this.context.getResources().getDimension(R.dimen.myAppPopuWinHeight);
- if (9999 == popuWinHeight)
- {
- popuWinHeight = ScreenInfo.SCREEN_HEIGHT/4;
- }
- m_popupWindow = new PopupWindow(contentView, LayoutParams.FILL_PARENT, (int)popuWinHeight, true);
像這種就是直接使用螢幕資訊:
- ///< 載入和設定布局
- contentView = LayoutInflater.from(context).inflate(R.layout.privatepopuwin, null, true);
- window = new PopupWindow(contentView, (int)ScreenInfo.SCREEN_WIDTH*2/5, (int)ScreenInfo.SCREEN_HEIGHT*2/5, true);
當然也是需要在布局檔案裡面使用dimen的...
- <TextView
- android:id="@+id/private_tipTV"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/private_tipTVMarginTop"
- android:layout_marginBottom="@dimen/private_tipTVMarginBottom"
- android:layout_centerHorizontal="true"
- android:text="@string/privatepassStr"
- android:textSize="@dimen/privatePopuTiptextSize" >
- </TextView>
最後大體適配了三個解析度,真機上也做了兩個適配,基本ok的。
到目前基本的本地的功能已經實現,還剩下菜單,刪除功能【關於刪除可能需要注意,因為刪除的內容是在適配器中的,而刪除按鈕是再header下,不再一個介面,得稍微處理下交換的問題】,應用中心的訊息推送完善;已知的Bug,下載時更新進度條的時候,條目間的進度資訊顯示錯亂!!! 有空就接著完善。。。