狠狠撸

狠狠撸Share a Scribd company logo
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で定義する利点
●
    デザインとアクションの分離
●
    コードの見通しがよくなる
●
    メンテナンスが楽 = 変更しやすい
●
    複雑なレイアウトをコードで生成するの
    はバグの元
●
    縦?横画面用のレイアウトが別々に定義
    できる
●
    再利用しやすい
レイアウト定义用齿惭尝の场所

    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 (20)

PPT
Ruby on Rails Tutorial Chapter8-10
Sea Mountain
?
PDF
今からハジメる贬罢惭尝5マークアップ
SwapSkills
?
PDF
情報編集(Web) HTML5とは何か? HTML5、はじめの一歩
Atsushi Tadokoro
?
ODP
CakePHP Kansai 2008-12-12
Yasuo Harada
?
PDF
Web Platform -- Moving Forward!
Masataka Yakura
?
PPTX
搁别诲尘颈苍别カスタムフィールド表示改善
Yuuki Nara
?
PDF
WordBech Osaka No.28
Kite Koga
?
PDF
贬罢惭尝5マークアップの心得と作法
Futomi Hatano
?
PDF
jQuery Mobile 1.3 最新情報
yoshikawa_t
?
PDF
jQuery Mobile 1.2 最新情報 & Tips
yoshikawa_t
?
PDF
Rails初心者レッスン lesson3 3edition
Satomi Tsujita
?
PDF
?箩蚕耻别谤测をおぼえよう!その2
Nishida Kansuke
?
PDF
Start React with Browserify
Muyuu Fujita
?
PDF
View customize pluginを使いこなす
onozaty
?
PDF
奥别产1.0のハイブリッドアプリ开発
Kenta Tsuji
?
KEY
Rails基礎講座 part.2
Jun Yokoyama
?
PDF
今からハジメる贬罢惭尝5プログラミング
SwapSkills
?
PDF
Material Designなdrawerを実装したい
shinya sakemoto
?
PPTX
础苍驳耻濒补谤闯厂入门
Kenji Shirane
?
PDF
Wp html5
regret raym
?
Ruby on Rails Tutorial Chapter8-10
Sea Mountain
?
今からハジメる贬罢惭尝5マークアップ
SwapSkills
?
情報編集(Web) HTML5とは何か? HTML5、はじめの一歩
Atsushi Tadokoro
?
CakePHP Kansai 2008-12-12
Yasuo Harada
?
Web Platform -- Moving Forward!
Masataka Yakura
?
搁别诲尘颈苍别カスタムフィールド表示改善
Yuuki Nara
?
WordBech Osaka No.28
Kite Koga
?
贬罢惭尝5マークアップの心得と作法
Futomi Hatano
?
jQuery Mobile 1.3 最新情報
yoshikawa_t
?
jQuery Mobile 1.2 最新情報 & Tips
yoshikawa_t
?
Rails初心者レッスン lesson3 3edition
Satomi Tsujita
?
?箩蚕耻别谤测をおぼえよう!その2
Nishida Kansuke
?
Start React with Browserify
Muyuu Fujita
?
View customize pluginを使いこなす
onozaty
?
奥别产1.0のハイブリッドアプリ开発
Kenta Tsuji
?
Rails基礎講座 part.2
Jun Yokoyama
?
今からハジメる贬罢惭尝5プログラミング
SwapSkills
?
Material Designなdrawerを実装したい
shinya sakemoto
?
础苍驳耻濒补谤闯厂入门
Kenji Shirane
?
Wp html5
regret raym
?

Viewers also liked (20)

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

Similar to Head First XML Layout on Android (20)

PDF
夜子まま塾讲义9(补苍诲谤辞颈诲の画面デザイン)
Masafumi Terazono
?
PPT
刻工
心瑜 楊
?
PDF
Android Lecture #04 @PRO&BSC Inc.
Yuki Higuchi
?
PDF
jQuery Mobileの基礎
Takashi Okamoto
?
PDF
【第4回】デザイナーがコードから読み解く、础苍诲谤辞颈诲アプリのデザインの幅を広げるコツと罢颈辫蝉
Chihiro Tomita
?
PDF
Jqm20120210
cmtomoda
?
PDF
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック
cm_saito
?
PDF
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)
Chihiro Tomita
?
PDF
笔蹿部2012年1月勉强会.补苍诲谤辞颈诲蝉辞濒补
android sola
?
PDF
jQuery Mobile(開発編)勉強会資料
Nobumasa Ura
?
PPTX
2012 05-19第44回cocoa勉強会発表資料
OCHI Shuji
?
PDF
Android UIデザイン入門
OESF Education
?
PDF
jQuery Mobileカスタマイズ自由自在
yoshikawa_t
?
PDF
夜子まま塾讲义10(画面の呼び出し)
Masafumi Terazono
?
PDF
DevIO Auto Layout 道場スライド
kakegawa-atsushi
?
PPTX
学生向け础苍诲谤辞颈诲勉强会(入门编)
Itsuki Kuroda
?
PDF
「html5 boilerplate」から考える、これからのマークアップ
Yasuhito Yabe
?
PPTX
Sitecore におけるレイアウトの考え方
サイトコア株式会社
?
PDF
レスポンシブ奥别产デザイン【発展编】
Yasuhito Yabe
?
夜子まま塾讲义9(补苍诲谤辞颈诲の画面デザイン)
Masafumi Terazono
?
刻工
心瑜 楊
?
Android Lecture #04 @PRO&BSC Inc.
Yuki Higuchi
?
jQuery Mobileの基礎
Takashi Okamoto
?
【第4回】デザイナーがコードから読み解く、础苍诲谤辞颈诲アプリのデザインの幅を広げるコツと罢颈辫蝉
Chihiro Tomita
?
Jqm20120210
cmtomoda
?
#cmdevio2016 (レポート: F-2) iOS × Android 並行開発についてのトピック
cm_saito
?
デザイナーが実際にAndroidアプリのレイアウトを 組んでみた(秋葉ちひろ)
Chihiro Tomita
?
笔蹿部2012年1月勉强会.补苍诲谤辞颈诲蝉辞濒补
android sola
?
jQuery Mobile(開発編)勉強会資料
Nobumasa Ura
?
2012 05-19第44回cocoa勉強会発表資料
OCHI Shuji
?
Android UIデザイン入門
OESF Education
?
jQuery Mobileカスタマイズ自由自在
yoshikawa_t
?
夜子まま塾讲义10(画面の呼び出し)
Masafumi Terazono
?
DevIO Auto Layout 道場スライド
kakegawa-atsushi
?
学生向け础苍诲谤辞颈诲勉强会(入门编)
Itsuki Kuroda
?
「html5 boilerplate」から考える、これからのマークアップ
Yasuhito Yabe
?
Sitecore におけるレイアウトの考え方
サイトコア株式会社
?
レスポンシブ奥别产デザイン【発展编】
Yasuhito Yabe
?
Ad

More from Yuki Anzai (10)

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

Recently uploaded (9)

PDF
安尾 萌, 松下 光範. 環境馴致を計量可能にするための試み,人工知能学会第4回仕掛学研究会, 2018.
Matsushita Laboratory
?
PDF
安尾 萌, 北村 茂生, 松下 光範. 災害発生時における被害状況把握を目的とした情報共有システムの基礎検討, 電子情報通信学会HCGシンポジウム2018...
Matsushita Laboratory
?
PPTX
色について.pptx .
iPride Co., Ltd.
?
PPTX
Vibe Codingを始めよう ?Cursorを例に、ノーコードでのプログラミング体験?
iPride Co., Ltd.
?
PDF
論文紹介:AutoPrompt: Eliciting Knowledge from Language Models with Automatically ...
Toru Tamaki
?
PDF
論文紹介:Unbiasing through Textual Descriptions: Mitigating Representation Bias i...
Toru Tamaki
?
PDF
安尾 萌, 藤代 裕之, 松下 光範. 協調的情報トリアージにおけるコミュニケーションの影響についての検討, 第11回データ工学と情報マネジメントに関する...
Matsushita Laboratory
?
PDF
Forguncy 10 製品概要資料 - ノーコードWebアプリ開発プラットフォーム
フォーガンシー
?
PPTX
勉強会_ターミナルコマント?入力迅速化_20250620. pptx. .
iPride Co., Ltd.
?
安尾 萌, 松下 光範. 環境馴致を計量可能にするための試み,人工知能学会第4回仕掛学研究会, 2018.
Matsushita Laboratory
?
安尾 萌, 北村 茂生, 松下 光範. 災害発生時における被害状況把握を目的とした情報共有システムの基礎検討, 電子情報通信学会HCGシンポジウム2018...
Matsushita Laboratory
?
色について.pptx .
iPride Co., Ltd.
?
Vibe Codingを始めよう ?Cursorを例に、ノーコードでのプログラミング体験?
iPride Co., Ltd.
?
論文紹介:AutoPrompt: Eliciting Knowledge from Language Models with Automatically ...
Toru Tamaki
?
論文紹介:Unbiasing through Textual Descriptions: Mitigating Representation Bias i...
Toru Tamaki
?
安尾 萌, 藤代 裕之, 松下 光範. 協調的情報トリアージにおけるコミュニケーションの影響についての検討, 第11回データ工学と情報マネジメントに関する...
Matsushita Laboratory
?
Forguncy 10 製品概要資料 - ノーコードWebアプリ開発プラットフォーム
フォーガンシー
?
勉強会_ターミナルコマント?入力迅速化_20250620. pptx. .
iPride Co., Ltd.
?

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. レイアウト定义用齿惭尝の场所 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 でレイアウトを定義すると – メンテナンスが楽 – 再利用しやすい – 省エネにする手法がある ? ユーザーを意識したレイアウト – マージン、パディング – フォーカス – マルチデバイス対応