仿迅雷之Android版-簡單說下粗糙的適配

來源:互聯網
上載者:User

仿迅雷之Android版-簡單說下粗糙的適配
由於介面的元素並不是很多,主要是彈窗,字型,位置,彈窗內的布局間距等那麼幾個,所以基本都是靠dimen來做的,同時稍微在產生彈窗布局的時候,通過代碼利用螢幕寬高,利用dimen的值來實現效果,基本還是可以滿足需求的;同樣:高手可以指點指點,或者飄過~~~
dimens.xml - 工程結構在http://blog.chinaunix.net/uid-25799257-id-4724749.html有描述

 
  1. <resources>

  2. <!-- Default screen margins, per the Android Design guidelines. -->
  3. <dimen name="activity_horizontal_margin">16dp</dimen>
  4. <dimen name="activity_vertical_margin">16dp</dimen>
  5. <dimen name="layout_menu_width">180dp</dimen>
  6. <dimen name="layout_menuItem_width">170dp</dimen>
  7. <dimen name="half_layout_menu_width">70dp</dimen>
  8. <dimen name="half_layout_menuIcon_width">50dp</dimen>
  9. <dimen name="layout_title_barItem_width">35.0dip</dimen>
  10. <dimen name="myAppPopuWinHeight">98.0dip</dimen>
  11. <dimen name="myAppPushDataShowTextVHeight">40.0dip</dimen>
  12. <dimen name="myAppPushDataShowTextVWidth">200.0dip</dimen>
  13. <dimen name="editSizeWidth">120.0dip</dimen>
  14. <dimen name="editSizeHeigth">40.0dip</dimen>
  15. <dimen name="private_tipTVMarginTop">100.0dip</dimen>
  16. <dimen name="private_tipTVMarginBottom">20.0dip</dimen>
  17. <dimen name="privatePassSureBtnWidth">80.0dip</dimen>
  18. <dimen name="privatePassSureBtnHeigth">60.0dip</dimen>
  19. <dimen name="privatePopuTiptextSize">10.0sp</dimen>
  20. <dimen name="textSize">18.0sp</dimen>
  21. </resources>
上面基本都是不同比例下,有一套這樣的檔案;有些直接在布局中使用,有些在代碼中使用,that is it.
比如(我的沒有的解析度會給出一個預設的9999dip);
 
  1. contentView = LayoutInflater.from(context).inflate(R.layout.myapppopuwin, null, true);
  2. ///< 擷取不同解析度下的我的App的彈窗的尺寸,並且如果沒有該尺寸,則設定為螢幕高度的1/4
  3. float popuWinHeight = this.context.getResources().getDimension(R.dimen.myAppPopuWinHeight);
  4. if (9999 == popuWinHeight)
  5. {
  6. popuWinHeight = ScreenInfo.SCREEN_HEIGHT/4;
  7. }
  8. m_popupWindow = new PopupWindow(contentView, LayoutParams.FILL_PARENT, (int)popuWinHeight, true);
像這種就是直接使用螢幕資訊:
 
  1. ///< 載入和設定布局
  2. contentView = LayoutInflater.from(context).inflate(R.layout.privatepopuwin, null, true);
  3. window = new PopupWindow(contentView, (int)ScreenInfo.SCREEN_WIDTH*2/5, (int)ScreenInfo.SCREEN_HEIGHT*2/5, true);
當然也是需要在布局檔案裡面使用dimen的...
 
  1. <TextView
  2. android:id="@+id/private_tipTV"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:layout_marginTop="@dimen/private_tipTVMarginTop"
  6. android:layout_marginBottom="@dimen/private_tipTVMarginBottom"
  7. android:layout_centerHorizontal="true"
  8. android:text="@string/privatepassStr"
  9. android:textSize="@dimen/privatePopuTiptextSize" >
  10. </TextView>

最後大體適配了三個解析度,真機上也做了兩個適配,基本ok的。

到目前基本的本地的功能已經實現,還剩下菜單,刪除功能【關於刪除可能需要注意,因為刪除的內容是在適配器中的,而刪除按鈕是再header下,不再一個介面,得稍微處理下交換的問題】,應用中心的訊息推送完善;已知的Bug,下載時更新進度條的時候,條目間的進度資訊顯示錯亂!!! 有空就接著完善。。。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.