ãããªã¢ã« ãã¶ã¤ã³ ã¯ãã«ãã¹ã¯ãªã¼ã³ã®ä¸çã«ããã、ãã¸ã¥ã¢ã«、ã¤ã³ã¿ã©ã¯ã·ã§ã³、ã¢ã¼ã·ã§ã³ãã¶ã¤ã³ã®å
æ¬çãªã¢ããã¼ãã§ã。Android 5.0 Lollipop ã¨ã¢ãããã¼ãããããµãã¼ã ã©ã¤ãã©ãªã¯、ãããªã¢ã« UI ã®ä½æããµãã¼ããã¾ã。以ä¸ã«ããªãã®ã¢ããªã«å°å
¥å¯è½ãªã¦ã£ã¸ã§ããã API、ããã¦ãããªã¢ã« ãã¶ã¤ã³ã®ä¸»ãªè¦ç´ ã«ã¤ãã¦èª¬æãã¾ã。
ã¿ã³ã¸ãã« ãµã¼ãã§ã¹
ãããªã¢ã« ãã¶ã¤ã³ã«ããã UI ã¯、ãã¸ã¿ã«ã®
ç´ã¨ã¤ã³ã¯ ã§ã§ãã¦ãã¾ã。ãµã¼ãã§ã¹ã¨ãããè½ã¨ãå½±ã¯、触ãããã¨ãã§ããç¯å²、触ãããã©ã®ããã«åãã、ã¨ãã£ãã¢ããªã±ã¼ã·ã§ã³ã®æ§é ãè¦è¦çã«è¡¨ç¾ãã¦ãã¾ã。ãã®ãã¸ã¿ã«åããããããªã¢ã«ã¯åããã、æ¡å¼µããã、å¤å½¢ããããããã¨ã§、æè»ãª UI ãå½¢æãã¾ã。
å½±ã®æå
ãµã¼ãã§ã¹ã®ä½ç½®ã¨æ·±åº¦ã¯、å
ã®ãããå
·åãå½±ã«å¾®å¦ãªå½±é¿ãä¸ãã¾ã。æ°ãã
elevation
ããããã£ã使ç¨ããã°、ãã¥ã¼ã® Z 軸ã«ãããä½ç½®ãæå®ã§ãã¾ã。ä½ç½®æ
å ±ãå
ã«、ãã¬ã¼ã ã¯ã¼ã¯ã¯ãªã¢ã«ã¿ã¤ã ã§ãã®ãã¥ã¼ãããå¾ãã«ããã¢ã¤ãã ã«å½±ãè½ã¨ãã¾ã。ã¬ã¤ã¢ã¦ãå
ã§
elevation
ã®è¨å®ãè¡ãã¾ã(åä½: dip)。
<ImageView …
android:elevation="8dp" />
ã¾ã、
ViewCompat ã®
getElevation()/setElevation()
(shim ãå©ç¨)ã使ç¨ãã¦、ã³ã¼ãä¸ã§è¨å®ãããã¨ãã§ãã¾ã。ãã¥ã¼ãè½ã¨ãå½±ã®å½¢ã¯åºæ¬çã«èæ¯ã®æ
å ±ããç®åºãããã¢ã¦ãã©ã¤ã³ã«ãã£ã¦æ±ºã¾ãã¾ã。ãã¨ãã°åå½¢ã®
drawable
ã
floating action button ã®èæ¯ã¨ãã¦è¨å®ãã¦ããå ´å、é©åãªå½¢ã®å½±ãè½ã¨ãã¨ãããã¨ã§ã。ãã¥ã¼ãè½ã¨ãå½±ã®å½¢ããã詳細ã«å¶å¾¡ãããå ´åã¯、
getOutline()
ã§
Outline ãã«ã¹ã¿ãã¤ãºã§ãã
ViewOutlineProvider ãè¨å®ãããã¨ãã§ãã¾ã。
ã«ã¼ã
ã«ã¼ã ã¯、ç¹å®ã®æ
å ±ãæã£ããµã¼ãã§ã¹ãä½æããä¸è¬çãªãã¿ã¼ã³ã§ã。
CardView ãµãã¼ã ã©ã¤ãã©ãªãã¢ã¦ãã©ã¤ã³ã¨å½±ãæä¾ããã®ã§、ã«ã¼ãã®ä½æã¯ç°¡åã§ã(æ§æ¥ã®ãã©ãããã©ã¼ã ã§ãåæ§ã®æåã§ã)。
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--ã«ã¼ãã®ã³ã³ãã³ã -->
</android.support.v7.widget.CardView>
ã«ã¼ãã®è¦ãç®ããã©ãããã©ã¼ã ãã¾ããã§çµ±ä¸ããããã«、
CardView
ã¯
FrameLayout
ãæ¡å¼µãã¦ãã、
elevation
ã¨è§ã®ä¸¸ã¿ã®åå¾ã®ããã©ã«ãå¤ãè¨å®ãã¾ã。ãããã¯å¿
è¦ã«å¿ãã¦
cardElevation
ã¨
cardCornerRadius
ã®å±æ§ãæ´æ°ãããã¨ã§ã«ã¹ã¿ãã¤ãºã§ãã¾ã。UI ã«å¥¥è¡ããããããæ¹æ³ã¯ã«ã¼ãã ãã§ã¯ãªãã®ã§、
ã«ã¼ãã°ãã使ããããªãããã« æ°ãã¤ãã¾ããã!
å°å·ç©ã®ãããªãã¶ã¤ã³
ã³ã³ãã³ãã主役ã«ãªããã、ãããªã¢ã« ãã¶ã¤ã³ã¯å°å·ç©ã®ãã¶ã¤ã³ã®ååã«ã®ã£ã¨ã、ãã£ããã¨ããã·ã³ãã«ãªã¬ã¤ã¢ã¦ããå®ç¾ãã¾ã。大èãã¤èãã¬ãããè²ã®é¸æ、æå³çãªä½ç½、è¯è³ªãªã¿ã¤ãã°ã©ãã£ã¨、ãã£ããã¨ãããã¼ã¹ã©ã¤ã³ã°ãªããã«ãã£ã¦é層、æ義、ç¦ç¹ãçã¿åºããã¾ã。
ã¿ã¤ãã°ã©ãã£
Android 5.0 ã§ã¯ã·ã¹ãã ãã©ã³ã Roboto ãã¢ãããã¼ããã、ç»é¢ãµã¤ãºã«ãã ãããããã¹ããç¾ãã、ã¯ãªã¢ã«è¡¨ç¤ºãã¾ã。ããã£ã¢ã ã¦ã§ã¤ãã追å ãã(
android:fontFamily="sans-serif-medium"
)、æ°ãã TextAppearance ã¹ã¿ã¤ã«ã¯æ¨å¥¨ããã¦ãã
ã¿ã¤ãã°ã©ã㣠ã¹ã±ã¼ã« ã«ã®ã£ã¨ã、èªã¿ãããã¨ã³ã³ãã³ãã®å¯åº¦ã®ãã©ã³ã¹ãã¨ãã¾ã。ãã¨ãã°、
android:textAppearance="@android:style/TextAppearance.Material.Title"
ã¨è¨å®ããã ã㧠「
Title
」ã®ã¹ã¿ã¤ã«ãé©ç¨ã§ãã¾ã。ãããã®ã¹ã¿ã¤ã«ã¯
AppCompat
ãµãã¼ã ã©ã¤ãã©ãªãéãã¦、æ§æ¥ã®ãã©ãããã©ã¼ã ã§ã使ç¨ã§ãã¾ã(
“@style/TextAppearance.AppCompat.Title”
ãªã©)
ã«ã©ã¼
ã¢ããªã®
ã«ã©ã¼ãã¬ãã ã¯ãã©ã³ãã£ã³ã°ãåæ§ãããããè¦ç´ ã§ã。ä¸è¨ã®ãããªãã¼ãå±æ§ãç¨ã㦠UI ã®ã³ã³ããã¼ã«è¦ç´ ãç°¡åã«è²ä»ãã§ããããã«ãã¾ãã。
colorPrimary
: ã¢ããªã®ãã©ã¤ããªè²ã§ã。Action Bar
ã®èæ¯、æè¿ã®ã¿ã¹ã¯ã®ã¿ã¤ãã«、ã¨ãã¸å¹æãªã©ã«ä½¿ããã¾ã
colorAccent
: ãã©ã¤ããªè²ãè£è¶³ããæããè²ã§ã。EditText
ã Switch
ãªã©ã®ãã¬ã¼ã ã¯ã¼ã¯ ã³ã³ããã¼ã«ã«ä½¿ããã¾ã
colorPrimaryDark
: ãã©ã¤ããªè²ã®æãããªã¨ã¼ã·ã§ã³ã§ã。Status Bar
ã«ä½¿ããã¾ã
ã³ã³ããã¼ã«è¦ç´ ã®è²ä»ããããããç´°ããè¡ãã«ã¯ä¸è¨ã®å±æ§ãåç
§ãã¦ãã ãã:
colorControlNormal、colorControlActivated、colorControlHighlight、colorButtonNormal、colorSwitchThumbNormal、colorEdgeEffect、statusBarColor、navigationBarColor
AppCompat
ã¯ä¸è¨ã®æ©è½ã®å¤ããæä¾ã、Lollipop æè¼åã®ãã©ãããã©ã¼ã ã§ãã³ã³ããã¼ã«è¦ç´ ã®è²ä»ããå¯è½ã«ãã¾ã。
ãã¤ãããã¯ã«ã©ã¼
ãããªã¢ã« ãã¶ã¤ã³ã§ã¯ç»åã«ãããã¦è²ãæµåçã«ä½¿ãåãããã¨ãæ¨å¥¨ãã¦ãã¾ã。ç¹ã«è²å½©è±ããªç»åãæ¡ç¨ãã¦ããå ´åã«æå¹ã§ã。æ°ãããã¬ãã ãµãã¼ã ã©ã¤ãã©ãªã¯、ç»åããããã¤ãã®è²ãæ½åºã㦠UI ã³ã³ããã¼ã«è¦ç´ ã®ã¹ã¿ã¤ã«ãæ½åºããè²ã«åããããã¨ãå¯è½ã«ã、ã¦ã¼ã¶ã¼ã¯æ²¡å
¥æãå¾ããã¨ãã§ãã¾ã。æ½åºããããã¬ããã«ã¯、æããè²、æããè²、èªã¿ããããèæ
®ããããã¹ãè²ãå«ã¾ãã¾ã。
Palette.generateAsync(bitmap,
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch vibrant =
palette.getVibrantSwatch();
if (swatch != null) {
// æããè²ãããã¨ãã¯
// ã¿ã¤ãã«ã® TextView ãæ´æ°ãã
titleView.setBackgroundColor(
vibrant.getRgb());
titleView.setTextColor(
vibrant.getTitleTextColor());
}
}
});
ãªã¢ãªãã£ã®ããåã
ã¿ã³ã¸ãã« ãµã¼ãã§ã¹ã¯æ ç»ã®å ´é¢åãæ¿ãã®ããã«çªç¶ã©ãããã¨ããªãç¾ãããã®ã§ã¯ãªã、ç¶ç¶æ§ãä¿ã¡ã¾ã。ãã®åãã¯ã¦ã¼ã¶ã¼ã®æ³¨æãä¿ã、空éçãªé¢ä¿æ§ãæ§ç¯ãã¾ã。ãããªã¢ã«ã¯ã¦ã¼ã¶ã¼ã®ã¿ããã«åå¿ã、ããããããå¤åã¯ã¿ãããããç®æãèµ·ç¹ã¨ãã¦åºããã¾ã。ã¦ã¼ã¶ã¼ãç解ããããããã«、ãã¹ã¦ã®åãã¯ãªãã¿ãããæå³ãããã®ã«ãªã£ã¦ãã¾ã。
Activity 㨠Fragment ã®é·ç§»
2 ã¤ã®ç»é¢ã§å
±éãã 「shared elements」(å
±æè¦ç´ ) ã宣è¨ãããã¨ã§、ç°ãªãç¶æ
ã¸ã®é·ç§»ãã¹ã ã¼ãºã«è¡ããã¨ãã§ãã¾ã。
album_grid.xml
…
<Imageview
…
android:transitionname="@string/transition_album_cover" />
album_details.xml
…
<Imageview
…
android:transitionname="@string/transition_album_cover" />
AlbumActivity.java
Intent intent = new Intent();
String transitionName = getString(R.string.transition_album_cover);
…
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
albumCoverImageView, // é·ç§»ãã¯ãã¾ããã¥ã¼
transitionName // é·ç§»å
ã®ãã¥ã¼ã® transitionName
);
ActivityCompat.startActivity(activity, intent, options.toBundle());
ããã§ã¯2ã¤ã®ç»é¢ã§åã
transitionName
ãå®ç¾©ãã¾ã。æ°ãã Activity ãéå§ãããã¨、ãã®é·ç§»ã¯èªåçã«å¦çããã¾ã。ã¾ã、è¦ç´ ãå
±æãã以å¤ã«ã、é·ç§»
éå§æ ã¨
çµäºæ ã®æ¼åºãè¡ããã¨ãå¯è½ã§ã。
ãªããã«å¹æ
ãããªã¢ã«ã¯ ink ripple
surface reaction ã§ã¦ã¼ã¶ã¼ã®ã¿ããã«åå¿ãã¾ã。
Theme.Material
ã使ç¨ãããç¶æ¿ããå ´å、
Button
ãªã©ã®ã³ã³ããã¼ã«ã¯ããã©ã«ã㧠ink ripple ã®åå¿ãã¿ãã¾ã(
?android:selectableItemBackground
ãåæ§ã§ã)。
drawable
ã«ãªããã«å¹æã追å ããã«ã¯、ä¸è¨ã®ããã«
Ripple
è¦ç´ ãè¨å®ãã¾ã。
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/accent_dark">
<item>
<shape android:shape="oval">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
ã¿ãããã¤ã³ããããªããã«å¹æãã¯ãã¾ããã、ã«ã¹ã¿ã ãã¥ã¼ã§ã¯
View#drawableHotspotChanged ã³ã¼ã«ããã¯ã«ã¦、
drawable
ã«ã¿ããä½ç½®ãä¼ããå¿
è¦ãããã¾ã。
StateListAnimator
ã¾ã、ãããªã¢ã«ã¯ç£ç³ãã¦ã¼ã¶ã¼ã®æã«å¸ãã¤ãããã«
æã¡ä¸ããã¾ã 。ãã®ãããªå¹æãå®ç¾ããããã«ã¯、
translationZ
å±æ§ãæ´»ç¨ãã¾ã。ãã㯠elevation ã¨ä¼¼ã¦ãã¾ãã、ä¸æçãªå¹æãããããããã«å©ç¨ãã¾ã(
Z = elevation + translationZ
ã¨ããããã«)。æ°ãã
stateListAnimator
å±æ§ãæ´»ç¨ããã°、ã¦ã¼ã¶ã¼ã®ã¿ããã«åå¿ãã¦
translationZ
ãç°¡åã«èª¿æ´ãããã¨ãå¯è½ã§ã(
Buttons
ã¯ããã©ã«ãã§ãã®ããã«åä½ãã¾ã)。
layout/your_layout.xml
<Imagebutton ...
android:statelistanimator="@anim/raise" />
anim/raise.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_pressed="true">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyname="translationZ"
android:valueto="@dimen/touch_raise"
android:valuetype="floatType" />
</item>
<item>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyname="translationZ"
android:valueto="0dp"
android:valuetype="floatType" />
</item>
</selector>
Reveal
æ°ããã³ã³ãã³ãã表示ãããé、ãããªã¢ã« ãã¶ã¤ã³ã®ç¹å¾´ãçãããé·ç§»æ¹æ³ã® 1 ã¤ã、æ¡å¤§ããåå½¢ãã¹ã¯ãå©ç¨ãããã®ã§ã。ãã®æ¹æ³ã¯、ã¿ããããä½ç½®ãã
å¤ã«åãã£ã¦æ¾å°ç¶ã«åºããã®ã§ 、ã¦ã¼ã¶ã¼ã®ã¿ãããã¤ã³ãããã¹ã¦ã®ãã©ã³ã¸ã·ã§ã³ã®å§ç¹ã§ãããã¨ãè£å¼·ãã¦ãã¾ã。ãããå®ç¾ããããã«ã¯æ¬¡ã®
Animator
ã使ç¨ãã¾ã。
Animator reveal = ViewAnimationUtils.createCircularReveal(
viewToReveal, // Reveal ããããã®æ°ãããã¥ã¼
centerX, // ãã¹ã¯ä¸å¿ã® x 座æ¨
centerY, // ãã¹ã¯ä¸å¿ã® y 座æ¨
startRadius, // éå§æã®ãã¹ã¯ã®åå¾
endRadius); // å®äºæã®ãã¹ã¯ã®åå¾
reveal.start();
Interpolator
ã¢ã¼ã·ã§ã³ã¯è¨ç®ãã¤ããã、ä¿æã§æ£ç¢ºã§ããã¹ãã§ã。ãã£ããã¨å§ã¾ã、ãã£ããã¨çµããå
¸åçãªé·ç§»ã¨ã¯ç°ãªã、ãããªã¢ã« ãã¶ã¤ã³ã«ããããªãã¸ã§ã¯ãã¯ç´ æ©ãåãå§ã、ãã£ããã¨æçµä½ç½®ã«ã¤ãã¾ã。ãªãã¸ã§ã¯ãã¯é·ç§»åä½æéã®ãã¡、ããé·ãæé、æçµä½ç½®ä»è¿ã«åå¨ãã¾ã。çµæã¨ãã¦ã¦ã¼ã¶ã¼ã¯é·ç§»åä½ãçµããã®ãå¾
ã¤å¿
è¦ããªããªã、ã¢ã¼ã·ã§ã³åã«ãããã¤ãã¹å¹æã¯æå°éã«æãããã¾ã。ãã®ãããªåä½ãå¯è½ã«ããã®ã¯、æ°ãã追å ããã
fast-in-slow-out interpolator ã§ã。
è¦ç´ ãç»é¢ãåºããå
¥ã£ããããå ´å、
ãã¼ã¯é度ã§è¡ãã®ã好ã¾ãã ã§ãã、è¦ç´ ãç»é¢å¤ã«åºãéã«ã¯
fast-out-linear-in interpolator ã、ç»é¢å
ã«å
¥ãéã«ã¯
linear-out-slow-in interpolator ãåèã«ãã¦ãã ãã。
é©å¿æ§ã®é«ããã¶ã¤ã³
ãããªã¢ã« ãã¶ã¤ã³ã«ãããæçµçãªæ ¸ã¨ãªãã³ã³ã»ããã¯、æè¨ãã大åãã¬ãã¾ã§ã®ãã¾ãã¾ãªå½¢・大ããã®ããã¤ã¹ã«é©å¿ãããã¶ã¤ã³ãä½ããã¨ã§ã。ãã®ãã¶ã¤ã³ã®ãã¯ããã¯ã«ãã£ã¦、ããããã®ããã¤ã¹ãå
±éã®ã·ã¹ãã ãç°ãªããã¥ã¼ã§å
·ç¾åããã¨ãããã¸ã§ã³ã®å®ç¾ãå¯è½ã«ãªãã¾ãã。åããã¤ã¹ã®ç»é¢ã®å¤§ãããæä½æ¹æ³ã«é©å¿ããããã«åãã¥ã¼ã調æ´ããä¸æ¹ã§、è²、ã¢ã¤ã³ã³、é層æ§é 、åè¦ç´ ã®ç©ºéçé¢ä¿æ§ã«ã¯çµ±ä¸æããããã¾ã。ãããªã¢ã« ãã¶ã¤ã³ ã·ã¹ãã ã¯、æ¡å¼µå¯è½ãªãã¶ã¤ã³ãä½æããã®ã«å½¹ç«ã¤æè»ãªã³ã³ãã¼ãã³ãã¨ãã¿ã¼ã³ãæä¾ãã¾ã。
Toolbar
Toolbar
ã¯
Action Bar
ãä¸è¬åããããã®ã§、åæ§ã®æ©è½ãåãã¤ã¤、ããé«ãæè»æ§ãæä¾ãã¾ã。é常ã®
Action Bar
ã¨ç°ãªãç¹ã¯、
Toolbar
ã¯é層å
ã®ãã¥ã¼ã® 1 ã¤ã§ããã¨ãããã¨ã§ã。ãã®ãã、
Toolbar
ã®ã¤ã³ã¹ã¿ã³ã¹ã¯å¥½ããªã¨ããã«é
ç½®ãããã¨ãã§ã、ä»ã®ãã¥ã¼ã¨å
±åãã¾ã。ããã«、åããä¸ããã、ã¹ã¯ãã¼ã« ã¤ãã³ãã«åå¿ãããããã§ãã¾ã。
Activity.setActionBar()
ãã³ã¼ã«ãããã¨ã§、
Toolbar
ã
Activity
ã®
Action Bar
ã¨ãã¦æ©è½ããããã¨ãã§ãã¾ã。
ä¸è¨ã®ä¾ã§ã¯、éã Toolbar ã¯é«ããæ¡å¼µãã、ã³ã³ãã³ãããªã¼ãã¼ã¬ã¤ãã¦ãã、ããã²ã¼ã·ã§ã³ãã¿ã³ãæä¾ãã¦ãã¾ã。ã¾ã、ãªã¹ãé¨åã¨è©³ç´°ãã¥ã¼ã«ã¯、ããã« 2 ã¤ã® toolbar ã使ããã¦ãããã¨ã«ã注ç®ãã¦ãã ãã。
Toolbar
ã®å°å
¥ã«ã¤ãã¦ã¯、
ãã¡ãã®è¨äº ãåç
§ãã¦ãã ãã。
ãããªã¢ã«åãé²ãã¾ããã
ãããªã¢ã« ãã¶ã¤ã³ã¯ç解ãããã、ç¾ãã、é©å¿æ§ã®é«ã、ã¢ã¼ã·ã§ã³ã«ããµããã¢ããªãä½ããã¨ãæ¯æ´ãã¾ã。ãã®è¨äºã、ã¿ãªãã¾ããããã®ååãã¢ããªã«é©ç¨ããããã£ããã¨ãªã、ãã®å®ç¾ã®ããã«æ°ãã API ã¨äºæç¨ã® API ãæ´»ç¨ããããã®æãããã¨ãªããã¨ãé¡ã£ã¦ããã¾ã。
Posted by
èæ¨ä½ä¸ Developer Relations Team
「æ¬è¨äºã¯ Android Developer Relations ãã¼ã ã® Chris Banes 㨠Nick Butcher ã 10 æ 24 æ¥ã« Android Developers blog ã«æ稿ãã「Implementing Material Design in Your Android app 」ã¨ããè¨äºãå
ã«、翻訳・ä½æãã¦ãã¾ã。詳ããã¯å
è¨äºãã覧ãã ãã。 - èæ¨」
ãããªã¢ã« ãã¶ã¤ã³ ã¯ãã«ãã¹ã¯ãªã¼ã³ã®ä¸çã«ããã、ãã¸ã¥ã¢ã«、ã¤ã³ã¿ã©ã¯ã·ã§ã³、ã¢ã¼ã·ã§ã³ãã¶ã¤ã³ã®å
æ¬çãªã¢ããã¼ãã§ã。Android 5.0 Lollipop ã¨ã¢ãããã¼ãããããµãã¼ã ã©ã¤ãã©ãªã¯、ãããªã¢ã« UI ã®ä½æããµãã¼ããã¾ã。以ä¸ã«ããªãã®ã¢ããªã«å°å
¥å¯è½ãªã¦ã£ã¸ã§ããã API、ããã¦ãããªã¢ã« ãã¶ã¤ã³ã®ä¸»ãªè¦ç´ ã«ã¤ãã¦èª¬æãã¾ã。
ã¿ã³ã¸ãã« ãµã¼ãã§ã¹
ãããªã¢ã« ãã¶ã¤ã³ã«ããã UI ã¯、ãã¸ã¿ã«ã®ç´ã¨ã¤ã³ã¯ ã§ã§ãã¦ãã¾ã。ãµã¼ãã§ã¹ã¨ãããè½ã¨ãå½±ã¯、触ãããã¨ãã§ããç¯å²、触ãããã©ã®ããã«åãã、ã¨ãã£ãã¢ããªã±ã¼ã·ã§ã³ã®æ§é ãè¦è¦çã«è¡¨ç¾ãã¦ãã¾ã。ãã®ãã¸ã¿ã«åããããããªã¢ã«ã¯åããã、æ¡å¼µããã、å¤å½¢ããããããã¨ã§、æè»ãª UI ãå½¢æãã¾ã。
å½±ã®æå
ãµã¼ãã§ã¹ã®ä½ç½®ã¨æ·±åº¦ã¯、å
ã®ãããå
·åãå½±ã«å¾®å¦ãªå½±é¿ãä¸ãã¾ã。æ°ãã elevation
ããããã£ã使ç¨ããã°、ãã¥ã¼ã® Z 軸ã«ãããä½ç½®ãæå®ã§ãã¾ã。ä½ç½®æ
å ±ãå
ã«、ãã¬ã¼ã ã¯ã¼ã¯ã¯ãªã¢ã«ã¿ã¤ã ã§ãã®ãã¥ã¼ãããå¾ãã«ããã¢ã¤ãã ã«å½±ãè½ã¨ãã¾ã。ã¬ã¤ã¢ã¦ãå
㧠elevation
ã®è¨å®ãè¡ãã¾ã(åä½: dip)。
<ImageView …
android:elevation="8dp" />
ã¾ã、ViewCompat ã® getElevation()/setElevation()
(shim ãå©ç¨)ã使ç¨ãã¦、ã³ã¼ãä¸ã§è¨å®ãããã¨ãã§ãã¾ã。ãã¥ã¼ãè½ã¨ãå½±ã®å½¢ã¯åºæ¬çã«èæ¯ã®æ
å ±ããç®åºãããã¢ã¦ãã©ã¤ã³ã«ãã£ã¦æ±ºã¾ãã¾ã。ãã¨ãã°å形㮠drawable
ã floating action button ã®èæ¯ã¨ãã¦è¨å®ãã¦ããå ´å、é©åãªå½¢ã®å½±ãè½ã¨ãã¨ãããã¨ã§ã。ãã¥ã¼ãè½ã¨ãå½±ã®å½¢ããã詳細ã«å¶å¾¡ãããå ´åã¯、getOutline()
㧠Outline ãã«ã¹ã¿ãã¤ãºã§ãã ViewOutlineProvider ãè¨å®ãããã¨ãã§ãã¾ã。
ã«ã¼ã
ã«ã¼ã ã¯、ç¹å®ã®æ
å ±ãæã£ããµã¼ãã§ã¹ãä½æããä¸è¬çãªãã¿ã¼ã³ã§ã。CardView ãµãã¼ã ã©ã¤ãã©ãªãã¢ã¦ãã©ã¤ã³ã¨å½±ãæä¾ããã®ã§、ã«ã¼ãã®ä½æã¯ç°¡åã§ã(æ§æ¥ã®ãã©ãããã©ã¼ã ã§ãåæ§ã®æåã§ã)。
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--ã«ã¼ãã®ã³ã³ãã³ã -->
</android.support.v7.widget.CardView>
ã«ã¼ãã®è¦ãç®ããã©ãããã©ã¼ã ãã¾ããã§çµ±ä¸ããããã«、CardView
㯠FrameLayout
ãæ¡å¼µãã¦ãã、elevation
ã¨è§ã®ä¸¸ã¿ã®åå¾ã®ããã©ã«ãå¤ãè¨å®ãã¾ã。ãããã¯å¿
è¦ã«å¿ã㦠cardElevation
㨠cardCornerRadius
ã®å±æ§ãæ´æ°ãããã¨ã§ã«ã¹ã¿ãã¤ãºã§ãã¾ã。UI ã«å¥¥è¡ããããããæ¹æ³ã¯ã«ã¼ãã ãã§ã¯ãªãã®ã§、ã«ã¼ãã°ãã使ããããªãããã« æ°ãã¤ãã¾ããã!
å°å·ç©ã®ãããªãã¶ã¤ã³
ã³ã³ãã³ãã主役ã«ãªããã、ãããªã¢ã« ãã¶ã¤ã³ã¯å°å·ç©ã®ãã¶ã¤ã³ã®ååã«ã®ã£ã¨ã、ãã£ããã¨ããã·ã³ãã«ãªã¬ã¤ã¢ã¦ããå®ç¾ãã¾ã。大èãã¤èãã¬ãããè²ã®é¸æ、æå³çãªä½ç½、è¯è³ªãªã¿ã¤ãã°ã©ãã£ã¨、ãã£ããã¨ãããã¼ã¹ã©ã¤ã³ã°ãªããã«ãã£ã¦é層、æ義、ç¦ç¹ãçã¿åºããã¾ã。
ã¿ã¤ãã°ã©ãã£
Android 5.0 ã§ã¯ã·ã¹ãã ãã©ã³ã Roboto ãã¢ãããã¼ããã、ç»é¢ãµã¤ãºã«ãã ãããããã¹ããç¾ãã、ã¯ãªã¢ã«è¡¨ç¤ºãã¾ã。ããã£ã¢ã ã¦ã§ã¤ãã追å ãã(android:fontFamily="sans-serif-medium"
)、æ°ãã TextAppearance ã¹ã¿ã¤ã«ã¯æ¨å¥¨ããã¦ããã¿ã¤ãã°ã©ã㣠ã¹ã±ã¼ã« ã«ã®ã£ã¨ã、èªã¿ãããã¨ã³ã³ãã³ãã®å¯åº¦ã®ãã©ã³ã¹ãã¨ãã¾ã。ãã¨ãã°、android:textAppearance="@android:style/TextAppearance.Material.Title"
ã¨è¨å®ããã ã㧠「Title
」ã®ã¹ã¿ã¤ã«ãé©ç¨ã§ãã¾ã。ãããã®ã¹ã¿ã¤ã«ã¯ AppCompat
ãµãã¼ã ã©ã¤ãã©ãªãéãã¦、æ§æ¥ã®ãã©ãããã©ã¼ã ã§ã使ç¨ã§ãã¾ã(“@style/TextAppearance.AppCompat.Title”
ãªã©)
ã«ã©ã¼
ã¢ããªã®ã«ã©ã¼ãã¬ãã ã¯ãã©ã³ãã£ã³ã°ãåæ§ãããããè¦ç´ ã§ã。ä¸è¨ã®ãããªãã¼ãå±æ§ãç¨ã㦠UI ã®ã³ã³ããã¼ã«è¦ç´ ãç°¡åã«è²ä»ãã§ããããã«ãã¾ãã。
colorPrimary
: ã¢ããªã®ãã©ã¤ããªè²ã§ã。Action Bar
ã®èæ¯、æè¿ã®ã¿ã¹ã¯ã®ã¿ã¤ãã«、ã¨ãã¸å¹æãªã©ã«ä½¿ããã¾ã
colorAccent
: ãã©ã¤ããªè²ãè£è¶³ããæããè²ã§ã。EditText
ã Switch
ãªã©ã®ãã¬ã¼ã ã¯ã¼ã¯ ã³ã³ããã¼ã«ã«ä½¿ããã¾ã
colorPrimaryDark
: ãã©ã¤ããªè²ã®æãããªã¨ã¼ã·ã§ã³ã§ã。Status Bar
ã«ä½¿ããã¾ã
ã³ã³ããã¼ã«è¦ç´ ã®è²ä»ããããããç´°ããè¡ãã«ã¯ä¸è¨ã®å±æ§ãåç
§ãã¦ãã ãã: colorControlNormal、colorControlActivated、colorControlHighlight、colorButtonNormal、colorSwitchThumbNormal、colorEdgeEffect、statusBarColor、navigationBarColor
AppCompat
ã¯ä¸è¨ã®æ©è½ã®å¤ããæä¾ã、Lollipop æè¼åã®ãã©ãããã©ã¼ã ã§ãã³ã³ããã¼ã«è¦ç´ ã®è²ä»ããå¯è½ã«ãã¾ã。
ãã¤ãããã¯ã«ã©ã¼
ãããªã¢ã« ãã¶ã¤ã³ã§ã¯ç»åã«ãããã¦è²ãæµåçã«ä½¿ãåãããã¨ãæ¨å¥¨ãã¦ãã¾ã。ç¹ã«è²å½©è±ããªç»åãæ¡ç¨ãã¦ããå ´åã«æå¹ã§ã。æ°ãããã¬ãã ãµãã¼ã ã©ã¤ãã©ãªã¯、ç»åããããã¤ãã®è²ãæ½åºã㦠UI ã³ã³ããã¼ã«è¦ç´ ã®ã¹ã¿ã¤ã«ãæ½åºããè²ã«åããããã¨ãå¯è½ã«ã、ã¦ã¼ã¶ã¼ã¯æ²¡å
¥æãå¾ããã¨ãã§ãã¾ã。æ½åºããããã¬ããã«ã¯、æããè²、æããè²、èªã¿ããããèæ
®ããããã¹ãè²ãå«ã¾ãã¾ã。
Palette.generateAsync(bitmap,
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch vibrant =
palette.getVibrantSwatch();
if (swatch != null) {
// æããè²ãããã¨ãã¯
// ã¿ã¤ãã«ã® TextView ãæ´æ°ãã
titleView.setBackgroundColor(
vibrant.getRgb());
titleView.setTextColor(
vibrant.getTitleTextColor());
}
}
});
ãªã¢ãªãã£ã®ããåã
ã¿ã³ã¸ãã« ãµã¼ãã§ã¹ã¯æ ç»ã®å ´é¢åãæ¿ãã®ããã«çªç¶ã©ãããã¨ããªãç¾ãããã®ã§ã¯ãªã、ç¶ç¶æ§ãä¿ã¡ã¾ã。ãã®åãã¯ã¦ã¼ã¶ã¼ã®æ³¨æãä¿ã、空éçãªé¢ä¿æ§ãæ§ç¯ãã¾ã。ãããªã¢ã«ã¯ã¦ã¼ã¶ã¼ã®ã¿ããã«åå¿ã、ããããããå¤åã¯ã¿ãããããç®æãèµ·ç¹ã¨ãã¦åºããã¾ã。ã¦ã¼ã¶ã¼ãç解ããããããã«、ãã¹ã¦ã®åãã¯ãªãã¿ãããæå³ãããã®ã«ãªã£ã¦ãã¾ã。
Activity 㨠Fragment ã®é·ç§»
2 ã¤ã®ç»é¢ã§å
±éãã 「shared elements」(å
±æè¦ç´ ) ã宣è¨ãããã¨ã§、ç°ãªãç¶æ
ã¸ã®é·ç§»ãã¹ã ã¼ãºã«è¡ããã¨ãã§ãã¾ã。
album_grid.xml
…
<Imageview
…
android:transitionname="@string/transition_album_cover" />
album_details.xml
…
<Imageview
…
android:transitionname="@string/transition_album_cover" />
AlbumActivity.java
Intent intent = new Intent();
String transitionName = getString(R.string.transition_album_cover);
…
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
albumCoverImageView, // é·ç§»ãã¯ãã¾ããã¥ã¼
transitionName // é·ç§»å
ã®ãã¥ã¼ã® transitionName
);
ActivityCompat.startActivity(activity, intent, options.toBundle());
ããã§ã¯2ã¤ã®ç»é¢ã§åã transitionName
ãå®ç¾©ãã¾ã。æ°ãã Activity ãéå§ãããã¨、ãã®é·ç§»ã¯èªåçã«å¦çããã¾ã。ã¾ã、è¦ç´ ãå
±æãã以å¤ã«ã、é·ç§»éå§æ ã¨çµäºæ ã®æ¼åºãè¡ããã¨ãå¯è½ã§ã。
ãªããã«å¹æ
ãããªã¢ã«ã¯ ink ripple surface reaction ã§ã¦ã¼ã¶ã¼ã®ã¿ããã«åå¿ãã¾ã。Theme.Material
ã使ç¨ãããç¶æ¿ããå ´å、Button
ãªã©ã®ã³ã³ããã¼ã«ã¯ããã©ã«ã㧠ink ripple ã®åå¿ãã¿ãã¾ã(?android:selectableItemBackground
ãåæ§ã§ã)。drawable
ã«ãªããã«å¹æã追å ããã«ã¯、ä¸è¨ã®ããã«Ripple
è¦ç´ ãè¨å®ãã¾ã。
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/accent_dark">
<item>
<shape android:shape="oval">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
ã¿ãããã¤ã³ããããªããã«å¹æãã¯ãã¾ããã、ã«ã¹ã¿ã ãã¥ã¼ã§ã¯ View#drawableHotspotChanged ã³ã¼ã«ããã¯ã«ã¦、drawable
ã«ã¿ããä½ç½®ãä¼ããå¿
è¦ãããã¾ã。
StateListAnimator
ã¾ã、ãããªã¢ã«ã¯ç£ç³ãã¦ã¼ã¶ã¼ã®æã«å¸ãã¤ãããã«æã¡ä¸ããã¾ã 。ãã®ãããªå¹æãå®ç¾ããããã«ã¯、translationZ
å±æ§ãæ´»ç¨ãã¾ã。ãã㯠elevation ã¨ä¼¼ã¦ãã¾ãã、ä¸æçãªå¹æãããããããã«å©ç¨ãã¾ã(Z = elevation + translationZ
ã¨ããããã«)。æ°ãã stateListAnimator
å±æ§ãæ´»ç¨ããã°、ã¦ã¼ã¶ã¼ã®ã¿ããã«åå¿ã㦠translationZ
ãç°¡åã«èª¿æ´ãããã¨ãå¯è½ã§ã(Buttons
ã¯ããã©ã«ãã§ãã®ããã«åä½ãã¾ã)。
layout/your_layout.xml
<Imagebutton ...
android:statelistanimator="@anim/raise" />
anim/raise.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_pressed="true">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyname="translationZ"
android:valueto="@dimen/touch_raise"
android:valuetype="floatType" />
</item>
<item>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyname="translationZ"
android:valueto="0dp"
android:valuetype="floatType" />
</item>
</selector>
Reveal
æ°ããã³ã³ãã³ãã表示ãããé、ãããªã¢ã« ãã¶ã¤ã³ã®ç¹å¾´ãçãããé·ç§»æ¹æ³ã® 1 ã¤ã、æ¡å¤§ããåå½¢ãã¹ã¯ãå©ç¨ãããã®ã§ã。ãã®æ¹æ³ã¯、ã¿ããããä½ç½®ããå¤ã«åãã£ã¦æ¾å°ç¶ã«åºããã®ã§ 、ã¦ã¼ã¶ã¼ã®ã¿ãããã¤ã³ãããã¹ã¦ã®ãã©ã³ã¸ã·ã§ã³ã®å§ç¹ã§ãããã¨ãè£å¼·ãã¦ãã¾ã。ãããå®ç¾ããããã«ã¯æ¬¡ã® Animator
ã使ç¨ãã¾ã。
Animator reveal = ViewAnimationUtils.createCircularReveal(
viewToReveal, // Reveal ããããã®æ°ãããã¥ã¼
centerX, // ãã¹ã¯ä¸å¿ã® x 座æ¨
centerY, // ãã¹ã¯ä¸å¿ã® y 座æ¨
startRadius, // éå§æã®ãã¹ã¯ã®åå¾
endRadius); // å®äºæã®ãã¹ã¯ã®åå¾
reveal.start();
Interpolator
ã¢ã¼ã·ã§ã³ã¯è¨ç®ãã¤ããã、ä¿æã§æ£ç¢ºã§ããã¹ãã§ã。ãã£ããã¨å§ã¾ã、ãã£ããã¨çµããå
¸åçãªé·ç§»ã¨ã¯ç°ãªã、ãããªã¢ã« ãã¶ã¤ã³ã«ããããªãã¸ã§ã¯ãã¯ç´ æ©ãåãå§ã、ãã£ããã¨æçµä½ç½®ã«ã¤ãã¾ã。ãªãã¸ã§ã¯ãã¯é·ç§»åä½æéã®ãã¡、ããé·ãæé、æçµä½ç½®ä»è¿ã«åå¨ãã¾ã。çµæã¨ãã¦ã¦ã¼ã¶ã¼ã¯é·ç§»åä½ãçµããã®ãå¾
ã¤å¿
è¦ããªããªã、ã¢ã¼ã·ã§ã³åã«ãããã¤ãã¹å¹æã¯æå°éã«æãããã¾ã。ãã®ãããªåä½ãå¯è½ã«ããã®ã¯、æ°ãã追å ããã fast-in-slow-out interpolator ã§ã。
è¦ç´ ãç»é¢ãåºããå
¥ã£ããããå ´å、ãã¼ã¯é度ã§è¡ãã®ã好ã¾ãã ã§ãã、è¦ç´ ãç»é¢å¤ã«åºãéã«ã¯ fast-out-linear-in interpolator ã、ç»é¢å
ã«å
¥ãéã«ã¯ linear-out-slow-in interpolator ãåèã«ãã¦ãã ãã。
é©å¿æ§ã®é«ããã¶ã¤ã³
ãããªã¢ã« ãã¶ã¤ã³ã«ãããæçµçãªæ ¸ã¨ãªãã³ã³ã»ããã¯、æè¨ãã大åãã¬ãã¾ã§ã®ãã¾ãã¾ãªå½¢・大ããã®ããã¤ã¹ã«é©å¿ãããã¶ã¤ã³ãä½ããã¨ã§ã。ãã®ãã¶ã¤ã³ã®ãã¯ããã¯ã«ãã£ã¦、ããããã®ããã¤ã¹ãå
±éã®ã·ã¹ãã ãç°ãªããã¥ã¼ã§å
·ç¾åããã¨ãããã¸ã§ã³ã®å®ç¾ãå¯è½ã«ãªãã¾ãã。åããã¤ã¹ã®ç»é¢ã®å¤§ãããæä½æ¹æ³ã«é©å¿ããããã«åãã¥ã¼ã調æ´ããä¸æ¹ã§、è²、ã¢ã¤ã³ã³、é層æ§é 、åè¦ç´ ã®ç©ºéçé¢ä¿æ§ã«ã¯çµ±ä¸æããããã¾ã。ãããªã¢ã« ãã¶ã¤ã³ ã·ã¹ãã ã¯、æ¡å¼µå¯è½ãªãã¶ã¤ã³ãä½æããã®ã«å½¹ç«ã¤æè»ãªã³ã³ãã¼ãã³ãã¨ãã¿ã¼ã³ãæä¾ãã¾ã。
Toolbar
Toolbar
㯠Action Bar
ãä¸è¬åããããã®ã§、åæ§ã®æ©è½ãåãã¤ã¤、ããé«ãæè»æ§ãæä¾ãã¾ã。é常㮠Action Bar
ã¨ç°ãªãç¹ã¯、Toolbar
ã¯é層å
ã®ãã¥ã¼ã® 1 ã¤ã§ããã¨ãããã¨ã§ã。ãã®ãã、Toolbar
ã®ã¤ã³ã¹ã¿ã³ã¹ã¯å¥½ããªã¨ããã«é
ç½®ãããã¨ãã§ã、ä»ã®ãã¥ã¼ã¨å
±åãã¾ã。ããã«、åããä¸ããã、ã¹ã¯ãã¼ã« ã¤ãã³ãã«åå¿ãããããã§ãã¾ã。Activity.setActionBar()
ãã³ã¼ã«ãããã¨ã§、Toolbar
ã Activity
ã® Action Bar
ã¨ãã¦æ©è½ããããã¨ãã§ãã¾ã。
ä¸è¨ã®ä¾ã§ã¯、éã Toolbar ã¯é«ããæ¡å¼µãã、ã³ã³ãã³ãããªã¼ãã¼ã¬ã¤ãã¦ãã、ããã²ã¼ã·ã§ã³ãã¿ã³ãæä¾ãã¦ãã¾ã。ã¾ã、ãªã¹ãé¨åã¨è©³ç´°ãã¥ã¼ã«ã¯、ããã« 2 ã¤ã® toolbar ã使ããã¦ãããã¨ã«ã注ç®ãã¦ãã ãã。
Toolbar
ã®å°å
¥ã«ã¤ãã¦ã¯、ãã¡ãã®è¨äº ãåç
§ãã¦ãã ãã。
ãããªã¢ã«åãé²ãã¾ããã
ãããªã¢ã« ãã¶ã¤ã³ã¯ç解ãããã、ç¾ãã、é©å¿æ§ã®é«ã、ã¢ã¼ã·ã§ã³ã«ããµããã¢ããªãä½ããã¨ãæ¯æ´ãã¾ã。ãã®è¨äºã、ã¿ãªãã¾ããããã®ååãã¢ããªã«é©ç¨ããããã£ããã¨ãªã、ãã®å®ç¾ã®ããã«æ°ãã API ã¨äºæç¨ã® API ãæ´»ç¨ããããã®æãããã¨ãªããã¨ãé¡ã£ã¦ããã¾ã。
Posted by èæ¨ä½ä¸ Developer Relations Team