2011-11-23 50 views
0

我正在爲我的應用程序設計一個頁面,其中我使用了兩個圖像和幾個垂直文字瀏覽。但是,當我使用不同的分辨率在模擬器中啓動應用程序時,圖像會變形。我使用了9-patch.png,但發現它已從Android 3.0中棄用,如果我正在開發2.3和更高版本的應用程序,我可以使用它嗎?爲多種屏幕分辨率創建圖像

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:background="#FFFFFF" android:orientation="horizontal"> 
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"> 
    <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:background="@drawable/auto" android:layout_height="wrap_content"></ImageView> 
    <LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="wrap_content"> 
     <TextView android:text="Home" android:textColor="#FF0000" android:id="@+id/textView8" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
     <TextView android:text=">Products" android:textColor="#FF0000" android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    </LinearLayout> 

    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView3" android:text="Replacement Parts" android:textColor="#000000" ></TextView> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView2" android:text="Accessories"  android:textColor="#000000" android:focusable="true"  android:layout_gravity="left" android:cursorVisible="true" ></TextView> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView6" android:text="Tools Equipment" android:textColor="#000000" ></TextView> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView4" android:text="Fluids Chemicals" android:textColor="#000000" ></TextView> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView5" android:text="Performance"  android:textColor="#000000" android:onClick="Perform" ></TextView> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/test_9patch_patched" > 
    </ImageView> 
</LinearLayout> 

請讓我知道,如果有任何其他方式除了9 patch.png圖像...

+0

有你嘗試使用權重?請確保您的圖像使用正確的比例類型... –

+0

非常感謝各位... 我徹底檢查了api,它似乎9補丁不被棄用,但它讓我想到有無數的Android設備(手機)不同的屏幕尺寸。因此,根據不同的屏幕尺寸調整圖像的最佳做法是什麼? –

回答

0

可以使不同像素大小的圖片爲不同的屏幕使用Photoshop或其他圖像編輯工具,並將它們放在hdpi,ldpi和mdpi可繪製文件夾中。

系統會根據設備的分辨率自動選擇圖片。

0

如果你的問題是「我可以在2.3及以上版本中使用九個補丁嗎?」我會問你「是的,的確,我這樣做沒有問題」。不幸的是,我不知道它自3.0以來已被棄用。我喜歡這個功能。

+0

已棄用?什麼取代它? –

1

我還沒有讀到3.0版本中已被棄用的9-patch。你能引用來源嗎?

如果要使用不同的圖像大小不同的屏幕上,你可以按照這個名單 (我覺得這個名字對於它的使用說明):

drawable-hdpi 
drawable-large-hdpi 
drawable-large-ldpi 
drawable-large-mdpi 
drawable-large-xhdpi 
drawable-ldpi 
drawable-mdpi 
drawable-normal-hdpi 
drawable-normal-ldpi 
drawable-normal-mdpi 
drawable-normal-xhdpi 
drawable-small-hdpi 
drawable-small-ldpi 
drawable-small-mdpi 
drawable-small-xhdpi 
drawable-v4 
drawable-xlarge 
drawable-xlarge-hdpi 
drawable-xlarge-ldpi 
drawable-xlarge-mdpi 
drawable-xlarge-xhdpi 

的佈局:

layout 
layout-land 
layout-land-ldpi 
layout-ldpi 
layout-xlarge-land-v11 
layout-xlarge-v11 
...