- The added line is THIS COLOR.
- The deleted line is THIS COLOR.
[[戻る>Android GUI部品]]
~
*文字表示 [#j81af56a]
文字表示には、2つの方法あり~
・Text View を使用する方法 ・・・ Widget的に文字を配置する~
・キャンパス上に 文字列を描画する方法 ・・・ グラフィックスとして文字を描画する使い方~
①Text View を使用する方法 ・・・ Widget部品的に文字を配置~
②キャンパス上に 文字列を直接描画する方法 ・・・ グラフィックスとして文字を描画~
~
* TextViewで描画 [#r0182c59]
-setText() で文字表示を実施~
・setText() で文字表示を実施~
setText("Hello");~
**Text View の属性 [#x81ec76b]
[[TextViewの属性>Android TextViewの属性]]
**ソース例 [#vfe70546]
・onDraw()で描画する必要は無い~
・TextViewではスクロールはできない。ScrollViewを使う。
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.view.ViewGroup.LayoutParams;
public class Test extends Activity {
@Override public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView test = new TextView(this);
test.setText("Hello World");
setContentView(test);
}
}
TextViewではスクロールはできない。ScrollViewを使う。
参考 : [[JavaDriveさんのページ>http://www.javadrive.jp/android/textview/index2.html]]~
参考 : [[雑記帳さんのページ>http://d.hatena.ne.jp/androidprogram/20100514/1273841754]]~
参考 : [[Android奔走記 さん>http://weide-dev.blogspot.com/2010/03/textview.html]]~
*Canvasに文字列描画 [#ke34c4ef]
onDraw時に canvas に Set Text
・Viewは自分で作成する~
・onDraw時に canvas に Set Text
** ソース [#mfb3b830]
package com.chinsan.string;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
//文字列の表示
public class StringEx extends Activity {
//初期化
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new StringView(this));
}
}
package com.chinsan.string;
import android.content.*;
import android.graphics.*;
import android.view.*;
//文字列の表示
public class StringView extends View {
//コンストラクタ
public StringView(Context context) {
super(context);
setBackgroundColor(Color.WHITE);
}
//描画
@Override
protected void onDraw(Canvas canvas) {
//描画オブジェクトの生成
Paint paint=new Paint();
paint.setAntiAlias(true);
//画面サイズ ・文字幅・アセント・ディセント
paint.setTextSize(12);
paint.setColor(0xFF000000);
canvas.drawText("画面サイズ:"+getWidth()+"x"+getHeight(),0,30,paint);
}
}
~
*参考 [#w163bc7a]
http://www.javadrive.jp/android/radiobutton/index2.html~
http://www.hakkaku.net/articles/20091102-593
~
~
[[戻る>Android GUI部品]]