まずはレイアウトの修正を行います。
eclipseの「パッケージエクスプローラ」にて、「res」→「layout」を選択し、右クリック→「新規」→「Android XML ファイル」をクリックします。
「リソース・タイプ」で「Layout」
「ファイル」に「helloworld.xml」
「ルート要素」で「LinearLayout」
を選択し「完了」をクリックします。
グラフィカルレイアウトエディタが立ち上がりますが、基礎を学ぶため、今回はXMLファイルを直接編集する方法をとります。
画面下にある「helloworld.xml」をクリックし、XMLエディタを開きます。
1 2 3 4 5 6 7 8 | <? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "match_parent" android:orientation = "vertical" > </ LinearLayout > |
1 2 3 4 5 6 7 8 9 10 11 12 | <? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "match_parent" android:orientation = "vertical" > < TextView android:text = "Hello World!" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> </ LinearLayout > |
eclipseの「パッケージエクスプローラ」にて、「src」→「パッケージ名」→「HelloWorldActivity.java」をダブルクリックします。
ソースエディタが立ち上がり、以下のように入力されていることを確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 | package com.blogspot.logroid.helloworld; import android.app.Activity; import android.os.Bundle; public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | package com.blogspot.logroid.helloworld; import android.app.Activity; import android.os.Bundle; public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.helloworld); } } |

0 件のコメント:
コメントを投稿