2011-04-21 75 views
1

嗨全部 我必須使用線性佈局與所有分辨率類型的設備,如480x800,480x854,320x480。 我使用x,y位置將元素放置在線性佈局中,同時爲320x480進行設計。我必須重新設計其他分辨率設備,因此需要更多時間。請以線性佈局給出所有分辨率的常用方法。提前致謝。如何爲所有設備分辨率設計

回答

2

請勿爲特定分辨率設計。使用屬性的值,layout_widthlayout_height值的組合wrap_contentmatch_parent以根據屏幕大小獲得不同的比例寬度,而不是硬編碼像素值。

例如,假設您要添加的四個按鈕一排,每佔用寬度相等,在屏幕的上方,由〜5個像素左頂偏:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="5dp" 
    android:gravity="top" 
    android:orientation="horizontal" 
    > 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 1" 
     /> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 2" 
     /> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 3" 
     /> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"  
     android:text="Button 4" 
     /> 
</LinearLayout> 

這將爲任何屏幕密度提供可靠的結果,而且您​​無需擔心某個像素值。用於填充的dp(與設備無關的像素)的使用也會根據密度而略有變化,因此無論分辨率如何,它都會保持一致的物理尺寸。

通讀關於LinearLayouts,FrameLayouts和RelativeLayouts的示例Android Developers site。你會很好地感受每個人的優點和缺點。

0

非常好的答案......我相信很多個人和企業都認爲Android是一個「設備」,而不清楚Android是否是一個「操作系統」。爲了正確顯示運行Android OS的所有設備的圖像,必須選擇支持多種設備,並根據Android OS進行開發,而不是運行Android OS的特定設備。我之前遇到過這個問題,我的老闆(當時)說:「你的測試設備需要什麼尺寸的圖像?我說」只是讓我的圖像!我被迫使用320x480圖像(根據測試設備),當區域經理在他的ThinkPad(和其他4個設備)上看到演示產品時,我終止了我的位置,因爲我的主管認爲Android是設備而不是操作系統...和公司的Android應用尚未完成。 我的意見持有決議‘是對某一設備或設備類型「支持多發設備是開發根據通用的Android OS開發’。

+0

感謝我有同樣的問題,解決了支持一些你有沒有得到職位? – 2012-02-11 12:24:36

+0

我在正確的地方,在正確的時間說話,我獲得了這個職位,但最終在發展中,你必須知道該做什麼,去哪裏或者去問誰...像這樣**這裏很棒的人在Stackoverflow **網絡。 – KaSiris 2012-02-11 18:39:33

相關問題