Upgrade to Pro — share decks privately, control downloads, hide ads and more …

border-left: 1dp solid #666666;

border-left: 1dp solid #666666;

【第17回】potatotips(iOS/Android開発Tips共有会) 発表資料 http://connpass.com/event/14143/

izumin5210/ViewBorderHelper: https://github.com/izumin5210/ViewBorderHelper

Masayuki Izumi

May 13, 2015
Tweet

More Decks by Masayuki Izumi

Other Decks in Technology

Transcript

  1. Ƅ Rekimoto Lab. at University of Tokyo (prev: Akashi-NCT) Ɠ

    Enginner at Wantedly, Inc. (Dmetlabel Corp. , Life is Tech, Inc.)
  2. XML 1 <layer-list> 2 <item android:top="-1dp" android:left="-1dp"> 3 <shape> 4

    <stroke android:width="1dp" android:color="#55ffffff" /> 5 </shape> 6 </item> 7 </layer-list>
  3. XML 1 <layer-list> 2 <item android:top="-1dp" android:left="-1dp"> 3 <shape> 4

    <stroke android:width="1dp" android:color="#55ffffff" /> 5 </shape> 6 </item> 7 </layer-list>
  4. 1 <layer-list> 2 <item android:top="-1dp" android:left="-1dp"> 3 <shape> 4 <stroke

    android:width="1dp" android:color="#55ffffff" /> 5 </shape> 6 </item> 7 </layer-list> 1dp 1dp 黒 : View 赤 : layer-list 内の item XML
  5. 1 <layer-list> 2 <item android:top="-1dp" android:left="-1dp"> 3 <shape> 4 <stroke

    android:width="1dp" android:color="#55ffffff" /> 5 </shape> 6 </item> 7 </layer-list> 1dp 1dp 黒 : View 赤 : layer-list 内の item XML
  6. XML 1 <layer-list> 2 <item android:top="-1dp" android:left="-1dp"> 3 <shape> 4

    <stroke android:width="1dp" android:color="#ffff9999" /> 5 </shape> 6 </item> 7 <item android:bottom="-1dp" android:right="-1dp"> 8 <shape> 9 <stroke android:width="1dp" android:color="#ff9999ff" /> 10 </shape> 11 </item> 12 </layer-list>
  7. Java 1 GradientDrawable layer = new GradientDrawable(); 2 layer.setStroke(BORDER_WIDTH, BORDER_COLOR);

    3 4 Drawable[] layers = new Drawable[]{layer}; 5 LayerDrawable layerDrawable = new LayerDrawable(layers); 6 layerDrawable.setLayerInset(0, 0, -BORDER_WIDTH, 0, -BORDER_WIDTH); 7 8 view.setBackground(layerDrawable); <layer-list /> : LayerDrawable <item /> : GradientDrawable
  8. Java 1 GradientDrawable layer = new GradientDrawable(); 2 layer.setStroke(BORDER_WIDTH, BORDER_COLOR);

    3 4 Drawable[] layers = new Drawable[]{layer}; 5 LayerDrawable layerDrawable = new LayerDrawable(layers); 6 layerDrawable.setLayerInset(0, 0, -BORDER_WIDTH, 0, -BORDER_WIDTH); 7 8 view.setBackground(layerDrawable); <layer-list /> : LayerDrawable <item /> : GradientDrawable
  9. CSS-Like な border 1 <AwesomeView 2 android:laoyut_width="wrap_content" 3 android:laoyut_height="wrap_content" 4

    app:border_color="0xffffffff" 5 app:border_right_width="1dp" 6 app:border_bottom_width="1dp" />
  10. CSS-Like な border 1 <AwesomeView 2 android:laoyut_width="wrap_content" 3 android:laoyut_height="wrap_content" 4

    app:border_color="0xffffffff" 5 app:border_right_width="1dp" 6 app:border_bottom_width="1dp" />
  11. izumin5210/ViewBorderHelper 1 class AwesomeView extends View { 2 public AwesomeView(Context

    context, AttributeSet attrs) { 3 super(context, attrs); 4 new ViewBorderHelper(context, attrs).setBorder(this); 5 } 6 }
  12. izumin5210/ViewBorderHelper 1 class AwesomeView extends View { 2 public AwesomeView(Context

    context, AttributeSet attrs) { 3 super(context, attrs); 4 new ViewBorderHelper(context, attrs).setBorder(this); 5 } 6 }
  13. まとめ Android で View の border 扱うのは面倒 (CSS に比べた場合) イイ感じのヘルパとか作ってややこしさ隠蔽

    (e.g. izumin5210/ViewBorderHelper) これで CSS わかる人なら Android のレイアウトが書ける! [ 要出典 ]