「TextView」の編集履歴(バックアップ)一覧はこちら

TextView」(2010/09/20 (月) 15:48:46) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

*TextViewの基本サンプル XML定義で表示する場合とオンコーディングで表示する場合の2パターンです。 **オンコーディングの場合 ***JAVAソース #highlight(){{ package jp.src_test; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.TextView; public class src_test extends Activity {   /** Called when the activity is first created. */   @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);    TextView test_txtview = new TextView(this);-------------------(1)    test_txtview.setText("TextViewのテスト表示");------------------(2)     test_txtview.setBackgroundColor(Color.rgb(255, 33, 66));-------(3)     test_txtview.setTextColor(Color.rgb(0,0,0));-------------------(4)     setContentView(test_txtview, new LayoutParams(--------------(5)         LayoutParams.FILL_PARENT,         LayoutParams.WRAP_CONTENT));   } } }} &bold(){(1) TextViewクラスを宣言します。} &bold(){(2) 表示する文字列を設定します。} &bold(){(3) 背景色を設定します。} &bold(){(4) 文字の色を設定します。} &bold(){(5) TextViewのサイズを指定して表示させます。} **XML定義の場合 ***JAVAソース #highlight(){{ package jp.src_test; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.TextView; public class src_test extends Activity {   /** Called when the activity is first created. */   @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.test_textview);-------(1)     TextView tview=(TextView)findViewById(R.id.txtview);-------(2)   } } }} &bold(){(1) "test_textview"という名前で作成されているXMLファイルを呼び出します。} &bold(){(2) 表示したTextViewのインスタンスを作成します。} ***XMLファイル #highlight(){{ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   > <TextView   android:id="@+id/txtview"-------------------(3)   android:layout_width="fill_parent"---------(4)   android:layout_height="wrap_content"---------(5)   android:background="#ff3366"---------(6)   android:textColor="#000000"---------(7)   android:text="TextViewのテスト表示"---------(8)   /> </LinearLayout> }} &bold(){(3) "txtview"という識別名でTextViewに一意になる識別子を与えます。} &bold(){(4) サイズを指定します。} &bold(){(5) サイズを指定します。} &bold(){(6) 背景色を指定します。} &bold(){(7) 文字色を指定します。} &bold(){(8) 表示する文字列を設定します。} &bold(){&color(blue){このサンプルでは"test_textview"というXMLファイルを定義してTextViewオブジェクトには"txtview"という識別子を与えています。 プログラム側は定義名と識別子で画面表示を行います。 }} **実行結果 #image(http://www35.atwiki.jp/andro_degu/pub/layout/LinearLayout01.gif,width=200,title=レイアウト(2),http://www35.atwiki.jp/andro_degu/pub/layout/LinearLayout01.gif,blank)
*TextViewの基本サンプル XML定義で表示する場合とオンコーディングで表示する場合の2パターンです。 **オンコーディングの場合 ***JAVAソース #highlight(){{ package jp.src_test; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.TextView; public class src_test extends Activity {   /** Called when the activity is first created. */   @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);    TextView test_txtview = new TextView(this);-------------------(1)    test_txtview.setText("TextViewのテスト表示");------------------(2)     test_txtview.setBackgroundColor(Color.rgb(255, 33, 66));-------(3)     test_txtview.setTextColor(Color.rgb(0,0,0));-------------------(4)     setContentView(test_txtview, new LayoutParams(--------------(5)         LayoutParams.FILL_PARENT,         LayoutParams.WRAP_CONTENT));   } } }} &bold(){(1) TextViewクラスを宣言します。} &bold(){(2) 表示する文字列を設定します。} &bold(){(3) 背景色を設定します。} &bold(){(4) 文字の色を設定します。} &bold(){(5) TextViewのサイズを指定して表示させます。} **XML定義の場合 ***JAVAソース #highlight(){{ package jp.src_test; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.TextView; public class src_test extends Activity {   /** Called when the activity is first created. */   @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.test_textview);-------(1)     TextView tview=(TextView)findViewById(R.id.txtview);-------(2)   } } }} &bold(){(1) "test_textview"という名前で作成されているXMLファイルを呼び出します。} &bold(){(2) 表示したTextViewのインスタンスを作成します。} ***XMLファイル #highlight(){{ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   > <TextView   android:id="@+id/txtview"-------------------(3)   android:layout_width="fill_parent"---------(4)   android:layout_height="wrap_content"---------(5)   android:background="#ff3366"---------(6)   android:textColor="#000000"---------(7)   android:text="TextViewのテスト表示"---------(8)   /> </LinearLayout> }} &bold(){(3) "txtview"という識別名でTextViewに一意になる識別子を与えます。} &bold(){(4) サイズを指定します。} &bold(){(5) サイズを指定します。} &bold(){(6) 背景色を指定します。} &bold(){(7) 文字色を指定します。} &bold(){(8) 表示する文字列を設定します。} &bold(){&color(blue){このサンプルでは"test_textview"というXMLファイルを定義してTextViewオブジェクトには"txtview"という識別子を与えています。 プログラム側は定義名と識別子で画面表示を行います。}} **実行結果 #image(http://www35.atwiki.jp/andro_degu/pub/widget/TextView01.gif,width=200,title=レイアウト(2),http://www35.atwiki.jp/andro_degu/pub/widget/TextView01.gif,blank)

表示オプション

横に並べて表示:
変化行の前後のみ表示:
目安箱バナー