2014-10-29 128 views
0

如何優化我的應用程序以支持多種屏幕尺寸? 我正在研究一個項目,其中大部分圖形都是XML可繪製的,沒有定義的大小。 我曾嘗試與值文件夾中的維度(ldpi,mpdi,etcetc),但那並沒有真正做這項工作。我遇到了一些屏幕出現的問題,所以我嘗試了爲每種屏幕尺寸創建不同的佈局,但同樣的事情發生,應用程序在4.3 ... 5「」設備上看起來不錯,但是當我啓動3.7模擬器時,應用程序看起來很糟糕,有些物品在屏幕外/被其他物品覆蓋。 我使用相對佈局,我沒有看到代碼的需要,但如果需要我會發布。 我的問題是:什麼是優化應用程序以支持多種屏幕尺寸的最佳方式?支持多種屏幕尺寸Android

回答

1

我覺得你的出發點應該是通過這個頁面由谷歌一下:https://developer.android.com/guide/practices/screens_support.html

而且,這裏有一些指針:

  • 自由使用「WRAP_CONTENT」和「match_parent」高度和寬度佈局屬性。避免,設定明確的尺寸在可能的情況
  • 當你需要設定明確的大小,考慮使用不同的屏幕上dimen.xml或考慮設置值語法親
  • 確保您可繪製,別有不同的清晰圖片'忘記可繪製的nodpi文件夾
-1

您應該爲每種屏幕尺寸(小,正常,大和X大)創建4個文件夾。 右鍵單擊編輯器中的res文件夾並選擇New - > AndroidResourceDirectory從Available qualifier中選擇大小並創建每種大小的文件夾。 祝你好運

+0

此方法已被棄用,因爲它與屏幕尺寸和新密度沒有關聯。 2014年的手機將是x-large,與2011平板電腦一樣。 – 2014-10-29 18:21:01

0

我發現的最好的方法是在用XML定義佈局時非常周到。在大多數情況下,你會發現你可以定義你的佈局,以便它們能夠在設備之間適當地擴展,直到你達到真正的高端。

拿這個佈局,例如:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/MainLinView1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/KeywordItemViewMain" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="@dimen/defViewMargin" 
    android:layout_marginRight="@dimen/defViewMargin" 
    android:layout_marginTop="@dimen/defViewMarginTopBottom" 
    android:layout_marginBottom="@dimen/defViewMarginTopBottom" 
    android:background="@drawable/rounded_corners_background" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:padding="@dimen/defViewPadding" > 

    <TextView 
     android:id="@+id/rowKeywordTitle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:padding="5dp" 
     android:text="@string/keywordrow_name" 
     android:textSize="15sp" 
     android:textStyle="bold" /> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/icons" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/KeywordItemViewMain" 
    android:layout_centerVertical="true" > 

    <ImageView 
     android:id="@+id/acknowledgedIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/handled" 
     android:padding="5dp" 
     android:src="@drawable/acknowledge_item_icon" /> 
</LinearLayout> 

填充母&總結的內容將是你最好的朋友。

我只使用小,正常,大和X大的文件夾時,我真的需要指定不同設計的電話之間的佈局或真正的高/低端屏幕尺寸,因爲我覺得它令人討厭做4/5編輯每次我想對佈局進行微小的修改。