2017-06-19 229 views
0

我有一個ImageView的就是這個樣子放在哪裏繪製的圖像爲特定屏幕大小

<ImageView 
android:layout_width = "wrap_content" 
android:layout_height="wrap_content" 
android:src = "@drawable/myimage"/> 

圖像文件「myimage.png」是在不同的密度的所有4個繪製文件夾。這個視圖在手機上看起來不錯。如果我在平板電腦上顯示它(例如10英寸),則圖像「看起來」太小,因爲有太多空間。

我知道我可以爲大屏幕尺寸創建佈局,但我在哪裏放置圖像文件的大尺寸?通過這種方式,圖像文件可以基於不僅密度採摘也是屏幕尺寸

謝謝

回答

0

您應該使用sw符號。

例如:

layout/activity_with_photo.xml 
layout-sw600dp/activity_with_photo.xml // that's a 7 inch tablet 
layout-sw720dp/activity_with_photo.xml // that's a nexus 9 and up 

,然後這些佈局更大的圖像

// here a 7 inch tabled with all the densities 
layout-mdpi-sw600dp/photo.png 
layout-hdpi-sw600dp/photo.png 
layout-xdpi-sw600dp/photo.png 
layout-xxdpi-sw600dp/photo.png 

// here a nexus 9 n up with all densities 
layout-mdpi-sw720dp/photo.png 
layout-hdpi-sw720dp/photo.png 
layout-xdpi-sw270dp/photo.png 
layout-xxdpi-sw720dp/photo.png 

另外,如果你在運行時做這些資源的適當的比例,你可以添加到no-dpi文件夾

layout-nodpi-sw600dp/photo.png 
layout-nodpi-sw270dp/photo.png 

但是,如果您只使用一個,請注意這裏:Bitmap too large to be uploaded into a texture

0

屏幕尺寸的特定資源由smallmediumlargexlarge表示。所以你需要一個drawable-small和/或layout-small文件夾等

來源:https://developer.android.com/guide/practices/screens_support.html

編輯:由於Android 3.2屏幕尺寸文件夾已過時。請使用密度文件夾

+0

哦我不知道你可以使用屏幕大小以及可繪製的名稱。所以,如果你有可繪製的小圖和drawable-xdpi的圖像,那麼在一個小的xdpi屏幕上,從哪個文件夾獲取圖像? – Snake

+0

我剛剛注意到這些已被棄用。請使用密度文件夾 – Aenadon

0

簡單的步驟: -

  1. 如果您正在使用股票的圖標。去這個網站https://material.io/icons/。選擇並下載大小爲48dp的圖標。

  2. 提取zip文件並選擇android下的所有文件夾,並將它們複製到項目的res文件夾中。而已。

enter image description here

+0

我不問密度。我在詢問屏幕尺寸 – Snake

+0

轉到res> values>添加新文件命名'維度'>在限定符中選擇'尺寸',並從小到大選擇'屏幕尺寸'。然後在新(x-large)維度文件下添加大屏幕維度。 –

0

一個棘手的方式設置的ImageView到fitcenter的scaleType和恆定的寬度和高度設置爲您的ImageView。將你的圖標擴展到指定的寬度和高度

<ImageView 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:scaleType="fitCenter" 
    android:src="@drawable/my_photo"/>