Support Library v23.2 overview

Support Library v23.2 overview

shibuya.apk #6で発表した内容です

C8097f17712da7f3123f28a4d3e6bdb9?s=128

Takahiro Shimokawa

March 16, 2016
Tweet

Transcript

  1. Support Library v23.2 overview @androhi 1

  2. About me 4 Zaim Inc. 4 GitHub / Twitter /

    Qiita 4 @androhi 4 DroidKaigi 2016 staff & speaker @androhi 2
  3. Agenda 4 v23.2ͷτϐοΫ 4 RecyclerViewͷࣗಈαΠζௐ੔ػೳ @androhi 3

  4. v23.2ͷτϐοΫ 1. VectorDrawableͷαϙʔτ 4 Ξχϝʔγϣϯ෇͖͸Ұ෦੍ݶ͋Γ 2. AppCompatͷDayNightςʔϚ 3. BottomSheetͷαϙʔτ 4.

    ΧελϜλϒʹϘτϜόʔͷ௥Ճ 5. AndroidTVͷLeanbackڧԽ @androhi 4
  5. VectorDrawable ͷαϙʔτ 4 VectorDrawableରԠ·ͱΊ @konifar 4 AppCompat v23.2 — Age of the

    vectors @androhi 5
  6. DayNight ςʔϚͷ௥Ճ <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> ... </style> // ΞϓϦશମʹઃఆ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

    // Activity΍Dialog୯ҐͰઃఆ AppCompatDelegate delegate = getDelegate(); delegate.setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); @androhi 6
  7. BottomSheet ͷαϙʔτ 4 αϙʔτϥΠϒϥϦ @yuichi_araki 4 BottomSheetBehaviorΛ࢖͏ @napplecomputer @androhi 7

  8. ΧελϜλϒͷϘ τϜόʔ ※ chrome v49 Ҏ্ @androhi 8

  9. ΧελϜλϒͷϘτϜόʔ // VectorDrawableͰ΋େৎ෉ʂ Bitmap icon1 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_room_24dp); Bitmap icon2

    = BitmapFactory.decodeResource(getResources(), R.drawable.ic_favorite_24dp); CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder() .setToolbarColor(getResources().getColor(R.color.colorPrimary)) .setSecondaryToolbarColor(getResources().getColor(R.color.colorPrimary)) // ௥ՃͰ͖Δͷ͸4ݸ·ͰɻͦΕҎ্͸IllegalStateException .addToolbarItem(1, icon1, "description1", pendingIntent) .addToolbarItem(2, icon2, "description2", pendingIntent) .build(); customTabsIntent.launchUrl(this, Uri.parse("http://zaim.net")); @androhi 9
  10. Leanback ڧԽ 4 GuidedStepFragment ͷେ෯ͳվળ 4 ࠓճ͸ࢼͤ·ͤΜͰͨ͠... @androhi 10

  11. RecyclerViewͷ ࣗಈαΠζௐ੔ػೳ @androhi 11

  12. WRAP_CONTENT ͷ༗ޮԽ RecyclerView ΛίϯςϯπͷαΠζʹԠͯ͡α ΠζมߋͰ͖ΔΑ͏ʹͳΓ·͢ɻͭ·ΓɺҎલ͸ Ͱ͖ͳ͔ͬͨ RecyclerView ͷੇ๏஋ʹ WRAP_CONTENT Λ࢖༻͢Δ͜ͱ͕Ͱ͖ΔΑ͏

    ʹͳ͍ͬͯ·͢ɻ — Google Developers Japan @androhi 12
  13. activity.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view"

    android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ff0000"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/recycler_view" android:background="#00ff00" android:text="Test"/> </RelativeLayout> @androhi 13
  14. list_item.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/list_text"

    android:layout_width="match_parent" android:layout_height="wrap_content"/> </RelativeLayout> @androhi 14
  15. @androhi 15

  16. @androhi 16

  17. ΋͜͠Μͳ list_item.xml ͩͬͨ Β... <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

    android:layout_height="match_parent"> <TextView android:id="@+id/list_text" android:layout_width="match_parent" android:layout_height="wrap_content"/> </RelativeLayout> @androhi 17
  18. @androhi 18

  19. v23.1 -> v23.2 ͷΞοϓσʔτ RecyclerView ͷ࢖༻Օॴ͸ཁ஫ҙ @androhi 19

  20. LayoutManager ͷมߋ ϏϧτΠϯͷ LayoutManager ΛܧঝͤͣɺΧε λϜͷ LayoutManager Λ࢖༻͍ͯ͠Δ৔߹ɺ͜ Ε͸ΦϓτΠϯ API

    ʹͳΓ·͢ɻ setAutoMeasureEnabled(true) Λݺͼग़͠ɺ ϝιουͷ Javadoc ʹৄ͘͠هࡌ͞Ε͍ͯΔͱ ͓Γɺࡉ͔ͳมߋΛՃ͑Δඞཁ͕͋Γ·͢ɻ — Google Developers Japan @androhi 20
  21. LayoutManager#setAutoMeasureEn abled(boolean) ϨΠΞ΢τͷଌఆ( onMeasure )Λɺ RecyclerView ͕ߦ͏( =true )ͷ͔ LayoutManager

    ͕ߦ͏( =false )ͷ͔Λఆٛ͢ Δϝιουɻ -> RecyclerView ͕ଌఆ͢Δ৔߹͸ɺࢠͷཁૉ͔ ΒαΠζΛࣗಈܭࢉ͢Δɻ @androhi 21
  22. v23.1 ͷ LinearLayoutManager // Constructor public LinearLayoutManager(Context context, int orientation,

    boolean reverseLayout) { setOrientation(orientation); setReverseLayout(reverseLayout); } @androhi 22
  23. v23.2 ͷ LinearLayoutManager public LinearLayoutManager(Context context, int orientation, boolean reverseLayout)

    { setOrientation(orientation); setReverseLayout(reverseLayout); setAutoMeasureEnabled(true); } @androhi 23
  24. LayoutManager ΛΧελϜͯ͠Δ ͳΒ onMeasure Λ override ͍ͯ͠Δ৔߹͸ɺΧε λϜ LayoutMnagerͷதͰ setAutoMeasureEnabled(false)

    ΛݺͿɻ @androhi 24
  25. ·ͱΊ 4 VectorDrawable αϙʔτ࠷ߴ 4 RecyclerView ͸ཁ஫ҙ @androhi 25