Viewの再利用方法まとめ

 Viewの再利用方法まとめ

potatotips#15でのLTです。
http://connpass.com/event/12140/

35e08efcf39d692f540047fb756eb4e3?s=128

konifar

March 12, 2015
Tweet

Transcript

  1. 7JFXͷ࠶ར༻ํ๏·ͱΊ ʢ໦ʣ খ੢༟հ

  2. !LPOJGBS w "OESPJE࡞ͬͯ·͢ɻ w ࠷ۙ͸8FCɻ w ಙౡݝࠤಹՏ಺ଜग़਎ɻ
 4BOTBOਆࢁΦϑΟεͷྡͷଜ

  3. 7JFXͷ࠶ར༻ํ๏  EJNFOTYNMɺDPMPSTYNM  ESBXBCMFYNM  TUZMFTYNM  JODMVEF 

    $VTUPN7JFX
  4. EJNFOTYNMɺDPMPSTYNM <TextView android:textColor="#757575" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="2" android:textSize="12dp" />

  5. EJNFOTYNMɺDPMPSTYNM <TextView android:textColor="#757575" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="2" android:textSize="12dp" />

  6. EJNFOTYNMɺDPMPSTYNM <TextView android:textColor="@color/grey600" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="2" android:textSize="@dimen/text_small" /> <color

    name=“grey600">#757575</color> <dimen name="text_small">12sp</dimen>
  7. ESBXBCMF <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white"> … </RelativeLayout>

  8. ESBXBCMF <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white"> … </RelativeLayout>

  9. ESBXBCMF <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable_bg_feedback"> … </RelativeLayout>

  10. ESBXBCMF <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.~~android"> ! <item android:state_pressed="true"> <shape

    android:shape="rectangle"> <solid android:color="#0a000000" /> </shape> </item> ! </selector>
  11. ESBXBCMF <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.~~android"> ! <item android:state_pressed="true"> <shape

    android:shape="rectangle"> <solid android:color="#0a000000" /> </shape> </item> ! </selector> ࢖͑ΔTUBUF͸ɺ4UBUF-JTU%SBXBCMFͷϖʔδࢀরɻ
  12. TUZMFTYNM <TextView android:textColor="@color/grey600" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="2" android:textSize="@dimen/text_small" />

  13. TUZMFTYNM <TextView android:textColor="@color/grey600" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="2" android:textSize="@dimen/text_small" />

  14. TUZMFTYNM <TextView style="@style/TextSub" android:layout_width="match_parent" android:layout_height="wrap_content" /> <style name="TextSub"> <item name="android:textSize">@dimen/text_small</item>

    <item name="android:textColor">@color/grey600</item> <item name=“android:gravity">center_vertical</item> <item name="android:maxLines">2</item> </style>
  15. TUZMFTYNM TUZMFT͸ෳ਺ͷYNMʹ෼͚ͯ؅ཧͨ͠ํ͕͍͍͔ ΋͠Ε·ͤΜɻ ྫ TUZMFT@IPNFYNMɺTUZMFT@EFUBJMTYNM ! ৄ͘͠͸<຋༁>BOESPJECFTUQSBDUJDFΛࢀরɻ

  16. JODMVEF <RelativeLayout android:layout_width="match_parent" android:layout_height=“wrap_content”> ! <ImageView … /> ! <RelativeLayout

    android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView … /> <TextView … /> <TextView … /> </RelativeLayout> ! </RelativeLayout>
  17. JODMVEF <RelativeLayout android:layout_width="match_parent" android:layout_height=“wrap_content”> ! <ImageView … /> ! <RelativeLayout

    android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView … /> <TextView … /> <TextView … /> </RelativeLayout> ! </RelativeLayout>
  18. JODMVEF <RelativeLayout android:layout_width="match_parent" android:layout_height=“wrap_content”> ! <ImageView … /> ! <include

    layout=“@layout/part_character_info" /> ! </RelativeLayout> 7JFXͷωετ͕ଟ͘ͳΓ͕ͪͳͷͰɺNFSHFͷ࢖͍ํΛ֮͑ͯ ͓͘ͱΑ͍ɻ 㱺8IBUJTUIFQVSQPTFPG"OESPJETUBHJO9.-MBZPVUT
  19. $VTUPN7JFX <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> ! <FrameLayout android:id="@+id/triangle" android:background=“@drawable/left_triangle" … />

    ! <TextView android:id=“@+id/txt_balloon"
 android:background="@drawable/bg_word_balloon" … /> ! </RelativeLayout>
  20. $VTUPN7JFX <com.konifar.whovoice.views.WordBalloonView android:id="@+id/balloon_word" android:layout_width="match_parent" android:layout_height=“wrap_content" />

  21. $VTUPN7JFX public class WordBalloonView extends RelativeLayout { ... public WordBalloonView(Context

    context, AttributeSet attrs) { super(context, attrs); inflate(context, R.layout.ui_word_balloon, this); ButterKnife.inject(this); ! TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.WordBalloonView); try { balloonText = a.getString( R.styleable.WordBalloonView_balloonText); } finally { a.recycle(); } ! mTxtBalloon.setText(balloonText); } ! public void setBalloonText(String balloonText) { mTxtBalloon.setText(balloonText); } }
  22. $VTUPN7JFX public class WordBalloonView extends RelativeLayout { ... public WordBalloonView(Context

    context, AttributeSet attrs) { super(context, attrs); inflate(context, R.layout.ui_word_balloon, this); ButterKnife.inject(this); ! TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.WordBalloonView); try { balloonText = a.getString( R.styleable.WordBalloonView_balloonText); } finally { a.recycle(); } ! mTxtBalloon.setText(balloonText); } ! public void setBalloonText(String balloonText) { mTxtBalloon.setText(balloonText); } }
  23. $VTUPN7JFX public class WordBalloonView extends RelativeLayout { ... public WordBalloonView(Context

    context, AttributeSet attrs) { super(context, attrs); inflate(context, R.layout.ui_word_balloon, this); ButterKnife.inject(this); ! TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.WordBalloonView); try { balloonText = a.getString( R.styleable.WordBalloonView_balloonText); } finally { a.recycle(); } ! mTxtBalloon.setText(balloonText); } ! public void setBalloonText(String balloonText) { mTxtBalloon.setText(balloonText); } }
  24. $VTUPN7JFX public class WordBalloonView extends RelativeLayout { ... public WordBalloonView(Context

    context, AttributeSet attrs) { super(context, attrs); inflate(context, R.layout.ui_word_balloon, this); ButterKnife.inject(this); ! TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.WordBalloonView); try { balloonText = a.getString( R.styleable.WordBalloonView_balloonText); } finally { a.recycle(); } ! mTxtBalloon.setText(balloonText); } ! public void setBalloonText(String balloonText) { mTxtBalloon.setText(balloonText); } }
  25. $VTUPN7JFX public class WordBalloonView extends RelativeLayout { ... public WordBalloonView(Context

    context, AttributeSet attrs) { super(context, attrs); inflate(context, R.layout.ui_word_balloon, this); ButterKnife.inject(this); ! TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.WordBalloonView); try { balloonText = a.getString( R.styleable.WordBalloonView_balloonText); } finally { a.recycle(); } ! mTxtBalloon.setText(balloonText); } ! public void setBalloonText(String balloonText) { mTxtBalloon.setText(balloonText); } }
  26. ·ͱΊ EJNFOTYNM DPMPSTYNM ESBXBCMFYNM Կ౓΋ग़ͯ͘Δ ϨΠΞ΢τ͔ TUZMFTYNM JODMVEF $VTUPN7JFX ෳ਺ͷ7JFXͰ

    ߏ੒͞Ε͍ͯΔ͔ ϩδοΫؚ͕· ΕΔ͔ ϨΠΞ΢τYNMʹ௚઀هड़ /P :FT /P :FT /P :FT σβΠϯʹ߹Θͤͯ࢖༻
  27. ͋Γ͕ͱ͏͍͟͝·ͨ͠ ٩ ๑❛ᴗ❛๑ ۶ גࣜձࣾحฌୂ ΤϯδχΞେืूதͰ͢