SlideShare a Scribd company logo
1 of 36
Download to read offline
Head First XML Layout
       on Android

        Yuki ANZAI
         @yanzm

   BootCamp 27 Sep 2010
自己紹介


       あんざいゆき
        @yanzm

日本Androidの会 女子部副部長
   デ部とかデザイン部とか。。。

Android アプリ開発者「Libraroid」
「BooXpress」「Wolfraroid」など
Question

    Android 経験値を教えてください!

1. Android開発、まったくやったことないです

2. HelloWorldはやりました

3. バリバリ開発してます
Layout
View の配置
画面のレイアウト方法

コードで生成
  動的に変更したい場合

XML で定義
  静的なレイアウトを定義する場合
XMLで定義する利点
●
    デザインとアクションの分離
●
    コードの見通しがよくなる
●
    メンテナンスが楽 = 変更しやすい
●
    複雑なレイアウトをコードで生成するの
    はバグの元
●
    縦・横画面用のレイアウトが別々に定義
    できる
●
    再利用しやすい
レイアウト定義用XMLの場所

    res/layout/ の下

    res/layout/flename.xml

    Eclipseで Android プロ
    ジェクトを作成すると、
    main.xml が作られる
HelloWorld Demo
HelloWorld main.xml
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
 xmlns:android="http://schemas.android.com/ap
 k/res/android"
    android:orientation="vertical"
    android:layout_width="fll_parent"
    android:layout_height="fll_parent"
    >
    <TextView
      android:layout_width="fll_parent"
      android:layout_height="wrap_content"
      android:text="@string/hello"
      />                           View
 </LinearLayout>
                 ViewGroup
   View の配置を定義するのが ViewGroup
LayoutGroup
LayoutGroup
    LinearLayout
    RelativeLayout
    TableLayout
    FrameLayout
    (AbsoluteLayout)
    ListView
    GridView
    TabHost
    …
LayoutGroup の注意点
• layout_width と layout_height は必須
• LayoutGroup は入れ子にできる
• View には親のレイアウトパラメータを指定
LinearLayout
LinearLayout
LinearLayout
<LinearLayout>
    <LinearLayout>
      <EditText />
      <Button />
      <Button />
    <LinearLayout>
      <LinearLayout>
        <TextView />
        <ImageView /> <LinearLayout>
        <LinearLayout> <ScrollView>
          <Button />      <TextView />
          <Button />    <Button />
      <ScrollView>    <LinearLayout>
        <TextView />    <Button />
                        <Button />
                        <Button />
                        <Button />
LinearLayout

•   fll_parent と wrap_content
•   android:weight
•   画面を区切って配置する方法に最適
•   複雑なレイアウトには不向き
fill_parent ・wrap_content
• android:height, android:width に指定
• fll_parent    : 親の幅一杯を指定
• wrap_content : View の中のコンテンツ
  がちょうど入る大きさ




                        fll_parent

                        wrap_content
android:layout_weight
• LinearLayout で余った領域を割り当て
  る時の重みを指定
• 高さ、幅の % 指定のようなもの



           wrap_content

           左だけ layout_weight=”1”

           両方 layout_weight=”1”

           左 layout_weight=”2”
           右 layout_weight=”1”
RelativeLayout
RelativeLayout

LinearLayout では
難しい
RelativeLayout

<RelativeLayout>
  <Button /> : 中心
        id=“@+id/center”
        centerInParent=“true”
            親(この場合画面)の中心
  <Button /> : 近畿
        id=“@+id/kinki”
        layout_below=“@id/center”
            中心の下
  <Button /> : 中国
        id=”@+id/chugoku”
        layout_toLeftOf=”@id/kinki”
        layout_alignTop=”@id/kinki”
            近畿の左
  <Button />
    ...
よりよいレイアウトヘ
ここちよいレイアウト

• マージン、パディングを適切に設定
  – android:layout_margin
  – android:padding
  – layout_margin は root View では使えない

• dipを使う!
   – px を使ったピクセル指定はだめ
margin と padding



   layout_margin
           padding
dip vs px

        • 上のボタン: 200 dip
        • 下のボタン: 200 px
padding
        • dip なら、画面に対す
          る割合が同じ

         Nexus One

         HT-03A
フォーカスハンドリング

• キーボード、トラックボール操作を意識する
• 今どこにフォーカスがある?
• スクロールバーにフォーカス
  – focusable=”true”
  – focusableInTouchMode=”true”
• フォーカスのリクエスト
  – <View> タグ内に <requestFocus /> を入れる
      1画面に1つだけ
  – コードからリクエスト
マルチデバイス対応

• nine-patch (img.9.png)
• maxHeight, maxWidth, minHeight, minWidth
• <dimen>
   – リソースとしてサイズを指定
   – <dimen name=”listHeight”>64dip</dimen>
   – コードからsetWidth(width)など
• Not use absolute layout
nine-patch

   • 拡大する領域を 1px で指定
   • sdk-dir/tools/draw9patch

nine-patch



not
nine-patch
より開発をスムーズに
レイアウトの再利用

• <include> タグ
   – <include
     layout="@layout/layout_resource”/>
• <merge> タグ
   – custom view を作るときに有用
   – 最適化のため、view-tree のレベルを削減
• ViewStubを使う
<include> tag

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
 xmlns:android="http://schemas.android.com/ap
 k/res/android"
    android:orientation="vertical"
    android:layout_width="fll_parent"
    android:layout_height="fll_parent" >
    <EditText
       android:layout_width="fll_parent"
       android:layout_height="wrap_content" />
    <Button
       android:layout_width="fll_parent"
       android:layout_height="wrap_content"
       android:text="Button" />
    <include
       layout="@layout/japanmap_layout" />
  </LinearLayout>
ViewStub

•   たまにしか使われない View に使う
•   dumb and lightweight view
•   dimension を持たない、何も描画しない
•   layout fle の中では ViewStub で定義
•   必要なときにコードから infate する
ViewStub
            <ViewStub
               // infate するための id
               android:id="@+id/stub_import"
               // infate したあと override する id
               android:infatedId="@+id/panel_import"
               // 置き換える layout fle
               android:layout="@layout/progress_overlay"
            />


infate() or visibility をセットする(とinfateされる)
((ViewStub) fndViewById(R.id.stub_import))
       .setVisibility(View.VISIBLE);
// or
View importPanel = ((ViewStub)fndViewById(R.id.stub_import))
       .infate();
効果的なレイアウト

• ListViewの子要素のXML定義の注意点
   – 何度も infate されるので簡素化
   – LinearLayout の入れ子よりも
     RelativeLayout 1個で実現すべし

            <LinearLayout>     <RelativeLayout>
             <ImageView />        <ImageView />
             <LinearLayout>       <TextView />
                <TextView />      <TextView />
                <TextView />
Summary

• XML でレイアウトを定義すると
  – メンテナンスが楽
  – 再利用しやすい
  – 省エネにする手法がある
• ユーザーを意識したレイアウト
  – マージン、パディング
  – フォーカス
  – マルチデバイス対応

More Related Content

What's hot

Ruby on Rails Tutorial Chapter8-10
Ruby on Rails Tutorial Chapter8-10Ruby on Rails Tutorial Chapter8-10
Ruby on Rails Tutorial Chapter8-10Sea Mountain
 
今からハジメるHTML5マークアップ
今からハジメるHTML5マークアップ今からハジメるHTML5マークアップ
今からハジメるHTML5マークアップSwapSkills
 
情報編集(Web) HTML5とは何か? HTML5、はじめの一歩
情報編集(Web)  HTML5とは何か? HTML5、はじめの一歩情報編集(Web)  HTML5とは何か? HTML5、はじめの一歩
情報編集(Web) HTML5とは何か? HTML5、はじめの一歩Atsushi Tadokoro
 
CakePHP Kansai 2008-12-12
CakePHP Kansai 2008-12-12CakePHP Kansai 2008-12-12
CakePHP Kansai 2008-12-12Yasuo Harada
 
Web Platform -- Moving Forward!
Web Platform -- Moving Forward!Web Platform -- Moving Forward!
Web Platform -- Moving Forward!Masataka Yakura
 
Redmineカスタムフィールド表示改善
Redmineカスタムフィールド表示改善Redmineカスタムフィールド表示改善
Redmineカスタムフィールド表示改善Yuuki Nara
 
WordBech Osaka No.28
WordBech Osaka No.28WordBech Osaka No.28
WordBech Osaka No.28Kite Koga
 
HTML5マークアップの心得と作法
HTML5マークアップの心得と作法HTML5マークアップの心得と作法
HTML5マークアップの心得と作法Futomi Hatano
 
jQuery Mobile 1.3 最新情報
jQuery Mobile 1.3 最新情報jQuery Mobile 1.3 最新情報
jQuery Mobile 1.3 最新情報yoshikawa_t
 
jQuery Mobile 1.2 最新情報 & Tips
jQuery Mobile 1.2 最新情報 & TipsjQuery Mobile 1.2 最新情報 & Tips
jQuery Mobile 1.2 最新情報 & Tipsyoshikawa_t
 
Rails初心者レッスン lesson3 3edition
Rails初心者レッスン lesson3 3editionRails初心者レッスン lesson3 3edition
Rails初心者レッスン lesson3 3editionSatomi Tsujita
 
⑯jQueryをおぼえよう!その2
⑯jQueryをおぼえよう!その2⑯jQueryをおぼえよう!その2
⑯jQueryをおぼえよう!その2Nishida Kansuke
 
Start React with Browserify
Start React with BrowserifyStart React with Browserify
Start React with BrowserifyMuyuu Fujita
 
View customize pluginを使いこなす
View customize pluginを使いこなすView customize pluginを使いこなす
View customize pluginを使いこなすonozaty
 
Web1.0のハイブリッドアプリ開発
Web1.0のハイブリッドアプリ開発Web1.0のハイブリッドアプリ開発
Web1.0のハイブリッドアプリ開発Kenta Tsuji
 
Rails基礎講座 part.2
Rails基礎講座 part.2Rails基礎講座 part.2
Rails基礎講座 part.2Jun Yokoyama
 
今からハジメるHTML5プログラミング
今からハジメるHTML5プログラミング今からハジメるHTML5プログラミング
今からハジメるHTML5プログラミングSwapSkills
 
Material Designなdrawerを実装したい
Material Designなdrawerを実装したいMaterial Designなdrawerを実装したい
Material Designなdrawerを実装したいshinya sakemoto
 

What's hot (20)

Ruby on Rails Tutorial Chapter8-10
Ruby on Rails Tutorial Chapter8-10Ruby on Rails Tutorial Chapter8-10
Ruby on Rails Tutorial Chapter8-10
 
今からハジメるHTML5マークアップ
今からハジメるHTML5マークアップ今からハジメるHTML5マークアップ
今からハジメるHTML5マークアップ
 
情報編集(Web) HTML5とは何か? HTML5、はじめの一歩
情報編集(Web)  HTML5とは何か? HTML5、はじめの一歩情報編集(Web)  HTML5とは何か? HTML5、はじめの一歩
情報編集(Web) HTML5とは何か? HTML5、はじめの一歩
 
CakePHP Kansai 2008-12-12
CakePHP Kansai 2008-12-12CakePHP Kansai 2008-12-12
CakePHP Kansai 2008-12-12
 
Web Platform -- Moving Forward!
Web Platform -- Moving Forward!Web Platform -- Moving Forward!
Web Platform -- Moving Forward!
 
Redmineカスタムフィールド表示改善
Redmineカスタムフィールド表示改善Redmineカスタムフィールド表示改善
Redmineカスタムフィールド表示改善
 
WordBech Osaka No.28
WordBech Osaka No.28WordBech Osaka No.28
WordBech Osaka No.28
 
HTML5マークアップの心得と作法
HTML5マークアップの心得と作法HTML5マークアップの心得と作法
HTML5マークアップの心得と作法
 
jQuery Mobile 1.3 最新情報
jQuery Mobile 1.3 最新情報jQuery Mobile 1.3 最新情報
jQuery Mobile 1.3 最新情報
 
jQuery Mobile 1.2 最新情報 & Tips
jQuery Mobile 1.2 最新情報 & TipsjQuery Mobile 1.2 最新情報 & Tips
jQuery Mobile 1.2 最新情報 & Tips
 
Rails初心者レッスン lesson3 3edition
Rails初心者レッスン lesson3 3editionRails初心者レッスン lesson3 3edition
Rails初心者レッスン lesson3 3edition
 
⑯jQueryをおぼえよう!その2
⑯jQueryをおぼえよう!その2⑯jQueryをおぼえよう!その2
⑯jQueryをおぼえよう!その2
 
Start React with Browserify
Start React with BrowserifyStart React with Browserify
Start React with Browserify
 
View customize pluginを使いこなす
View customize pluginを使いこなすView customize pluginを使いこなす
View customize pluginを使いこなす
 
Web1.0のハイブリッドアプリ開発
Web1.0のハイブリッドアプリ開発Web1.0のハイブリッドアプリ開発
Web1.0のハイブリッドアプリ開発
 
Rails基礎講座 part.2
Rails基礎講座 part.2Rails基礎講座 part.2
Rails基礎講座 part.2
 
今からハジメるHTML5プログラミング
今からハジメるHTML5プログラミング今からハジメるHTML5プログラミング
今からハジメるHTML5プログラミング
 
Material Designなdrawerを実装したい
Material Designなdrawerを実装したいMaterial Designなdrawerを実装したい
Material Designなdrawerを実装したい
 
AngularJS入門
AngularJS入門AngularJS入門
AngularJS入門
 
Wp html5
Wp html5Wp html5
Wp html5
 

Viewers also liked

Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -Yuki Anzai
 
Android Layout Cookbook Seminor
Android Layout Cookbook SeminorAndroid Layout Cookbook Seminor
Android Layout Cookbook SeminorYuki Anzai
 
Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷Yuki Anzai
 
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?Yuki Anzai
 
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼ アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼ Yuki Anzai
 
Sublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEWSublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEWYuki Anzai
 
User Interface 「UI ラーニング・パターン」 - ABC2014s
User Interface 「UI ラーニング・パターン」 - ABC2014sUser Interface 「UI ラーニング・パターン」 - ABC2014s
User Interface 「UI ラーニング・パターン」 - ABC2014sChihiro Tomita
 
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談Yuki Anzai
 
Fragment を使ってみよう
Fragment を使ってみようFragment を使ってみよう
Fragment を使ってみようYuki Anzai
 
Watch face アプリを公開してみた
Watch face アプリを公開してみたWatch face アプリを公開してみた
Watch face アプリを公開してみたYuki Anzai
 
マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向Yuki Anzai
 
Android Layout 3分クッキング
Android Layout 3分クッキングAndroid Layout 3分クッキング
Android Layout 3分クッキングYuki Anzai
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewYuki Anzai
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)Khaled Anaqwa
 
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Yuki Anzai
 
Android software development – the first few hours
Android software development – the first few hoursAndroid software development – the first few hours
Android software development – the first few hourssjmarsh
 
Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!
Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!
Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!encafe
 

Viewers also liked (20)

Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -
 
Android Layout Cookbook Seminor
Android Layout Cookbook SeminorAndroid Layout Cookbook Seminor
Android Layout Cookbook Seminor
 
Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷
 
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
 
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼ アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
 
Sublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEWSublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEW
 
User Interface 「UI ラーニング・パターン」 - ABC2014s
User Interface 「UI ラーニング・パターン」 - ABC2014sUser Interface 「UI ラーニング・パターン」 - ABC2014s
User Interface 「UI ラーニング・パターン」 - ABC2014s
 
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
 
Fragment を使ってみよう
Fragment を使ってみようFragment を使ってみよう
Fragment を使ってみよう
 
Watch face アプリを公開してみた
Watch face アプリを公開してみたWatch face アプリを公開してみた
Watch face アプリを公開してみた
 
マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向
 
Android Layout 3分クッキング
Android Layout 3分クッキングAndroid Layout 3分クッキング
Android Layout 3分クッキング
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListView
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
 
Fragment の利用パターン
Fragment の利用パターンFragment の利用パターン
Fragment の利用パターン
 
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016
 
Android development first steps
Android development   first stepsAndroid development   first steps
Android development first steps
 
Android software development – the first few hours
Android software development – the first few hoursAndroid software development – the first few hours
Android software development – the first few hours
 
Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!
Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!
Gadget1 R2 ガジェットカフェでソーシャル電子工作を始めよう!
 
Basic Android Layout
Basic Android LayoutBasic Android Layout
Basic Android Layout
 

Similar to Head First XML Layout on Android

夜子まま塾講義9(androidの画面デザイン)
夜子まま塾講義9(androidの画面デザイン)夜子まま塾講義9(androidの画面デザイン)
夜子まま塾講義9(androidの画面デザイン)Masafumi Terazono
 
Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Yuki Higuchi
 
【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTips
【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTips【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTips
【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTipsChihiro Tomita
 
Jqm20120210
Jqm20120210Jqm20120210
Jqm20120210cmtomoda
 
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピックcm_saito
 
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)Chihiro Tomita
 
Pf部2012年1月勉強会.androidsola
Pf部2012年1月勉強会.androidsolaPf部2012年1月勉強会.androidsola
Pf部2012年1月勉強会.androidsolaandroid sola
 
jQuery Mobile(開発編)勉強会資料
jQuery Mobile(開発編)勉強会資料jQuery Mobile(開発編)勉強会資料
jQuery Mobile(開発編)勉強会資料Nobumasa Ura
 
2012 05-19第44回cocoa勉強会発表資料
2012 05-19第44回cocoa勉強会発表資料2012 05-19第44回cocoa勉強会発表資料
2012 05-19第44回cocoa勉強会発表資料OCHI Shuji
 
Android UIデザイン入門
Android UIデザイン入門Android UIデザイン入門
Android UIデザイン入門OESF Education
 
jQuery Mobileカスタマイズ自由自在
jQuery Mobileカスタマイズ自由自在jQuery Mobileカスタマイズ自由自在
jQuery Mobileカスタマイズ自由自在yoshikawa_t
 
夜子まま塾講義10(画面の呼び出し)
夜子まま塾講義10(画面の呼び出し)夜子まま塾講義10(画面の呼び出し)
夜子まま塾講義10(画面の呼び出し)Masafumi Terazono
 
DevIO Auto Layout 道場スライド
DevIO Auto Layout 道場スライドDevIO Auto Layout 道場スライド
DevIO Auto Layout 道場スライドkakegawa-atsushi
 
学生向けAndroid勉強会(入門編)
学生向けAndroid勉強会(入門編)学生向けAndroid勉強会(入門編)
学生向けAndroid勉強会(入門編)Itsuki Kuroda
 
「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップYasuhito Yabe
 
Sitecore におけるレイアウトの考え方
Sitecore におけるレイアウトの考え方Sitecore におけるレイアウトの考え方
Sitecore におけるレイアウトの考え方サイトコア株式会社
 
レスポンシブWebデザイン【発展編】
レスポンシブWebデザイン【発展編】レスポンシブWebデザイン【発展編】
レスポンシブWebデザイン【発展編】Yasuhito Yabe
 

Similar to Head First XML Layout on Android (20)

夜子まま塾講義9(androidの画面デザイン)
夜子まま塾講義9(androidの画面デザイン)夜子まま塾講義9(androidの画面デザイン)
夜子まま塾講義9(androidの画面デザイン)
 
刻工
刻工刻工
刻工
 
Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.
 
jQuery Mobileの基礎
jQuery Mobileの基礎jQuery Mobileの基礎
jQuery Mobileの基礎
 
【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTips
【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTips【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTips
【第4回】デザイナーがコードから読み解く、Androidアプリのデザインの幅を広げるコツとTips
 
Jqm20120210
Jqm20120210Jqm20120210
Jqm20120210
 
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック
 
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)
 
Pf部2012年1月勉強会.androidsola
Pf部2012年1月勉強会.androidsolaPf部2012年1月勉強会.androidsola
Pf部2012年1月勉強会.androidsola
 
jQuery Mobile(開発編)勉強会資料
jQuery Mobile(開発編)勉強会資料jQuery Mobile(開発編)勉強会資料
jQuery Mobile(開発編)勉強会資料
 
2012 05-19第44回cocoa勉強会発表資料
2012 05-19第44回cocoa勉強会発表資料2012 05-19第44回cocoa勉強会発表資料
2012 05-19第44回cocoa勉強会発表資料
 
Android UIデザイン入門
Android UIデザイン入門Android UIデザイン入門
Android UIデザイン入門
 
jQuery Mobileカスタマイズ自由自在
jQuery Mobileカスタマイズ自由自在jQuery Mobileカスタマイズ自由自在
jQuery Mobileカスタマイズ自由自在
 
夜子まま塾講義10(画面の呼び出し)
夜子まま塾講義10(画面の呼び出し)夜子まま塾講義10(画面の呼び出し)
夜子まま塾講義10(画面の呼び出し)
 
DevIO Auto Layout 道場スライド
DevIO Auto Layout 道場スライドDevIO Auto Layout 道場スライド
DevIO Auto Layout 道場スライド
 
学生向けAndroid勉強会(入門編)
学生向けAndroid勉強会(入門編)学生向けAndroid勉強会(入門編)
学生向けAndroid勉強会(入門編)
 
「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ
 
Sitecore におけるレイアウトの考え方
Sitecore におけるレイアウトの考え方Sitecore におけるレイアウトの考え方
Sitecore におけるレイアウトの考え方
 
iOS6 Auto Layout
iOS6 Auto LayoutiOS6 Auto Layout
iOS6 Auto Layout
 
レスポンシブWebデザイン【発展編】
レスポンシブWebデザイン【発展編】レスポンシブWebデザイン【発展編】
レスポンシブWebデザイン【発展編】
 

More from Yuki Anzai

droidgirls Recyclerview
droidgirls Recyclerviewdroidgirls Recyclerview
droidgirls RecyclerviewYuki Anzai
 
Androidオールスターズ2016 yanzm
Androidオールスターズ2016 yanzmAndroidオールスターズ2016 yanzm
Androidオールスターズ2016 yanzmYuki Anzai
 
Whats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in FukuokaWhats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in FukuokaYuki Anzai
 
What's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in FukuokaWhat's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in FukuokaYuki Anzai
 
How to read "marble diagram"
How to read "marble diagram"How to read "marble diagram"
How to read "marble diagram"Yuki Anzai
 
Master of RecyclerView
Master of RecyclerViewMaster of RecyclerView
Master of RecyclerViewYuki Anzai
 
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -Yuki Anzai
 
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」Yuki Anzai
 
ボクの開発スタイル
ボクの開発スタイルボクの開発スタイル
ボクの開発スタイルYuki Anzai
 
application Next Generation presented by android女子部
application Next Generation presented by android女子部application Next Generation presented by android女子部
application Next Generation presented by android女子部Yuki Anzai
 

More from Yuki Anzai (10)

droidgirls Recyclerview
droidgirls Recyclerviewdroidgirls Recyclerview
droidgirls Recyclerview
 
Androidオールスターズ2016 yanzm
Androidオールスターズ2016 yanzmAndroidオールスターズ2016 yanzm
Androidオールスターズ2016 yanzm
 
Whats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in FukuokaWhats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in Fukuoka
 
What's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in FukuokaWhat's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in Fukuoka
 
How to read "marble diagram"
How to read "marble diagram"How to read "marble diagram"
How to read "marble diagram"
 
Master of RecyclerView
Master of RecyclerViewMaster of RecyclerView
Master of RecyclerView
 
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
 
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
 
ボクの開発スタイル
ボクの開発スタイルボクの開発スタイル
ボクの開発スタイル
 
application Next Generation presented by android女子部
application Next Generation presented by android女子部application Next Generation presented by android女子部
application Next Generation presented by android女子部
 

Recently uploaded

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 

Recently uploaded (10)

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 

Head First XML Layout on Android

  • 1. Head First XML Layout on Android Yuki ANZAI @yanzm BootCamp 27 Sep 2010
  • 2. 自己紹介 あんざいゆき @yanzm 日本Androidの会 女子部副部長 デ部とかデザイン部とか。。。 Android アプリ開発者「Libraroid」 「BooXpress」「Wolfraroid」など
  • 3. Question Android 経験値を教えてください! 1. Android開発、まったくやったことないです 2. HelloWorldはやりました 3. バリバリ開発してます
  • 7. XMLで定義する利点 ● デザインとアクションの分離 ● コードの見通しがよくなる ● メンテナンスが楽 = 変更しやすい ● 複雑なレイアウトをコードで生成するの はバグの元 ● 縦・横画面用のレイアウトが別々に定義 できる ● 再利用しやすい
  • 8. レイアウト定義用XMLの場所 res/layout/ の下 res/layout/flename.xml Eclipseで Android プロ ジェクトを作成すると、 main.xml が作られる
  • 10. HelloWorld main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/ap k/res/android" android:orientation="vertical" android:layout_width="fll_parent" android:layout_height="fll_parent" > <TextView android:layout_width="fll_parent" android:layout_height="wrap_content" android:text="@string/hello" /> View </LinearLayout> ViewGroup View の配置を定義するのが ViewGroup
  • 12. LayoutGroup LinearLayout RelativeLayout TableLayout FrameLayout (AbsoluteLayout) ListView GridView TabHost …
  • 13. LayoutGroup の注意点 • layout_width と layout_height は必須 • LayoutGroup は入れ子にできる • View には親のレイアウトパラメータを指定
  • 16. LinearLayout <LinearLayout> <LinearLayout> <EditText /> <Button /> <Button /> <LinearLayout> <LinearLayout> <TextView /> <ImageView /> <LinearLayout> <LinearLayout> <ScrollView> <Button /> <TextView /> <Button /> <Button /> <ScrollView> <LinearLayout> <TextView /> <Button /> <Button /> <Button /> <Button />
  • 17. LinearLayout • fll_parent と wrap_content • android:weight • 画面を区切って配置する方法に最適 • 複雑なレイアウトには不向き
  • 18. fill_parent ・wrap_content • android:height, android:width に指定 • fll_parent : 親の幅一杯を指定 • wrap_content : View の中のコンテンツ がちょうど入る大きさ fll_parent wrap_content
  • 19. android:layout_weight • LinearLayout で余った領域を割り当て る時の重みを指定 • 高さ、幅の % 指定のようなもの wrap_content 左だけ layout_weight=”1” 両方 layout_weight=”1” 左 layout_weight=”2” 右 layout_weight=”1”
  • 22. RelativeLayout <RelativeLayout> <Button /> : 中心 id=“@+id/center” centerInParent=“true” 親(この場合画面)の中心 <Button /> : 近畿 id=“@+id/kinki” layout_below=“@id/center” 中心の下 <Button /> : 中国 id=”@+id/chugoku” layout_toLeftOf=”@id/kinki” layout_alignTop=”@id/kinki” 近畿の左 <Button /> ...
  • 24. ここちよいレイアウト • マージン、パディングを適切に設定 – android:layout_margin – android:padding – layout_margin は root View では使えない • dipを使う! – px を使ったピクセル指定はだめ
  • 25. margin と padding layout_margin padding
  • 26. dip vs px • 上のボタン: 200 dip • 下のボタン: 200 px padding • dip なら、画面に対す る割合が同じ Nexus One HT-03A
  • 27. フォーカスハンドリング • キーボード、トラックボール操作を意識する • 今どこにフォーカスがある? • スクロールバーにフォーカス – focusable=”true” – focusableInTouchMode=”true” • フォーカスのリクエスト – <View> タグ内に <requestFocus /> を入れる 1画面に1つだけ – コードからリクエスト
  • 28. マルチデバイス対応 • nine-patch (img.9.png) • maxHeight, maxWidth, minHeight, minWidth • <dimen> – リソースとしてサイズを指定 – <dimen name=”listHeight”>64dip</dimen> – コードからsetWidth(width)など • Not use absolute layout
  • 29. nine-patch • 拡大する領域を 1px で指定 • sdk-dir/tools/draw9patch nine-patch not nine-patch
  • 31. レイアウトの再利用 • <include> タグ – <include layout="@layout/layout_resource”/> • <merge> タグ – custom view を作るときに有用 – 最適化のため、view-tree のレベルを削減 • ViewStubを使う
  • 32. <include> tag <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/ap k/res/android" android:orientation="vertical" android:layout_width="fll_parent" android:layout_height="fll_parent" > <EditText android:layout_width="fll_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fll_parent" android:layout_height="wrap_content" android:text="Button" /> <include layout="@layout/japanmap_layout" /> </LinearLayout>
  • 33. ViewStub • たまにしか使われない View に使う • dumb and lightweight view • dimension を持たない、何も描画しない • layout fle の中では ViewStub で定義 • 必要なときにコードから infate する
  • 34. ViewStub <ViewStub // infate するための id android:id="@+id/stub_import" // infate したあと override する id android:infatedId="@+id/panel_import" // 置き換える layout fle android:layout="@layout/progress_overlay" /> infate() or visibility をセットする(とinfateされる) ((ViewStub) fndViewById(R.id.stub_import)) .setVisibility(View.VISIBLE); // or View importPanel = ((ViewStub)fndViewById(R.id.stub_import)) .infate();
  • 35. 効果的なレイアウト • ListViewの子要素のXML定義の注意点 – 何度も infate されるので簡素化 – LinearLayout の入れ子よりも RelativeLayout 1個で実現すべし <LinearLayout> <RelativeLayout> <ImageView /> <ImageView /> <LinearLayout> <TextView /> <TextView /> <TextView /> <TextView />
  • 36. Summary • XML でレイアウトを定義すると – メンテナンスが楽 – 再利用しやすい – 省エネにする手法がある • ユーザーを意識したレイアウト – マージン、パディング – フォーカス – マルチデバイス対応