Android應用的Material設計中圖片的相關處理指南_Android

來源:互聯網
上載者:User

可伸縮的向量圖片不會丟失清晰度,並且單一顏色的app-icon是完美的
可定義一個bitmap作為透明度(alpha)和運行時的顏色
可對一個bitmap image取色,會取出它比較顯眼的顏色
官網地址:https://developer.android.com/training/material/drawables.html

以下圖片的功能能協助你在app中實現Material設計:

  • 圖片著色
  • 顏色提取
  • 向量圖片

Tint Drawable Resources  為圖片資源染色

在Android 5.0(API層級21)及以上,你可以將圖片和9-patch定義為掩飾透明度。你能使用顏色資源(如,?android:attr/colorPrimary)或主題屬性來給它們上色。通常,你只需建立這些資源一次,且自動匹配你的主題為它們上色。
可以為BitmapDrawable和NinePatchDrawable 的對象使用setTint(int tint)進行染色。也可以在xml中定義android:tint和android:tintMode屬性。
·關於setTint(int tint)的參數,可以是一個@color/下的屬性,也可以是一個xml的selector,selector中的item是使用了數位,如:

 <selector xmlns:android="http://schemas.android.com/apk/res/android">  <item android:state_focused="true" android:color="@color/testcolor1"/>  <item android:state_pressed="true" android:state_enabled="false" android:color="@color/testcolor2" />  <item android:state_enabled="false" android:color="@color/testcolor3" />  <item android:color="@color/testcolor5"/> </selector>

·關於xml中定義屬性,如:

<?xmlversion="1.0"encoding="utf-8"?><nine-patchxmlns:android="http://schemas.android.com/apk/res/android"   android:tint="@color/abc_primary_text_material_light"   android:tintMode="src_over"  ... ></nine-patch>

Extract Prominent Colors from an Image  從圖片抽取明顯的顏色
在api21上的support-v7庫中有一個android-support-v7-palette.jar,它能夠讓你從圖片中抽取一些顯眼的顏色:

Palette p = Palette.generate(Bitmap bitmap);
  • 鮮豔的                p.getVibrantColor(int defaultColor);
  • 鮮豔的黑暗         p.getDarkVibrantColor(int defaultColor);
  • 鮮豔的明亮         p.getLightVibrantColor(int defaultColor);
  • 柔和的                p.getMutedColor(int defaultColor);
  • 柔和的黑暗         p.getDarkMutedColor(int defaultColor);
  • 柔和的明亮         p.getLightMutedColor(int defaultColor);

Palette.generate(),用於在後台線程中執行,如果在前台線程中建立Palette對象,那麼可以使用Palette.generateAsync()。

Create Vector Drawables  建立向量圖片
在Android 5.0(API層級21)及以上 可以建立向量圖片,如下面的例子可以繪製一個心形的向量圖:

<!-- res/drawable/heart.xml --><vector xmlns:android="http://schemas.android.com/apk/res/android"  <!-- intrinsic size of the drawable -->  android:height="256dp"  android:width="256dp"  <!-- size of the virtual canvas -->  android:viewportWidth="32"  android:viewportHeight="32"> <!-- draw a path --> <path android:fillColor="#8fff"   android:pathData="M20.5,9.5            c-1.955,0,-3.83,1.268,-4.5,3            c-0.67,-1.732,-2.547,-3,-4.5,-3            C8.957,9.5,7,11.432,7,14            c0,3.53,3.793,6.257,9,11.5            c5.207,-5.242,9,-7.97,9,-11.5            C25,11.432,23.043,9.5,20.5,9.5z" /></vector>

向量圖片在Android中使用VectorDrawble對象與之對應。path的更多資訊請見:http://www.w3.org/TR/SVG11/paths.html#PathData。

設計標準範例

選用圖片

描述具體事物,優先使用照片。然後可以考慮使用插畫。
圖片上的文字

圖片上的文字,需要淡淡的遮罩確保其可讀性。深色的遮罩透明度在20%-40%之間,淺色的遮罩透明度在40%-60%之間。

對於帶有文字的大幅圖片,遮罩文字地區,不要遮住整張圖片。

可以使用半透明的主色蓋住圖片。
提取顏色

Android L可以從圖片中提取主色,運用在其他UI元素上。
圖片載入過程

圖片的載入過程非常講究,透明度、曝光度、飽和度3個指標依次變化,效果相當細膩。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.