import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
public class FontTest extends Activity
{
class RenderView extends View
{
Paint paint;
Typeface font;
Rect bounds = new Rect();
public RenderView(Context context)
{
super(context);
paint = new Paint();
font = Typeface.createFromAsset(context.getAssets(), "font.ttf");
}
protected void onDraw(Canvas canvas)
{
paint.setColor(Color.YELLOW);
paint.setTypeface(font);
paint.setTextSize(28);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("Hello, World!",
canvas.getWidth()/2,
100,
paint);
String text = "이 글은 어떻게 출력될까?";
paint.setColor(Color.WHITE);
paint.setTextSize(18);
paint.setTextAlign(Paint.Align.LEFT);
paint.getTextBounds(text, 0, text.length(), bounds);
canvas.drawText(
text,
canvas.getWidth() - bounds.width(),
140,
paint);
invalidate();
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new RenderView(this));
}
}
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
public class FontTest extends Activity
{
class RenderView extends View
{
Paint paint;
Typeface font;
Rect bounds = new Rect();
public RenderView(Context context)
{
super(context);
paint = new Paint();
font = Typeface.createFromAsset(context.getAssets(), "font.ttf");
}
protected void onDraw(Canvas canvas)
{
paint.setColor(Color.YELLOW);
paint.setTypeface(font);
paint.setTextSize(28);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("Hello, World!",
canvas.getWidth()/2,
100,
paint);
String text = "이 글은 어떻게 출력될까?";
paint.setColor(Color.WHITE);
paint.setTextSize(18);
paint.setTextAlign(Paint.Align.LEFT);
paint.getTextBounds(text, 0, text.length(), bounds);
canvas.drawText(
text,
canvas.getWidth() - bounds.width(),
140,
paint);
invalidate();
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new RenderView(this));
}
}
'코드조각모음' 카테고리의 다른 글
[iOS] Pan, Pinch, Rotation Gesture 동시에 사용하기 (0) | 2012.06.01 |
---|---|
[android015] SurfaceView, UI스레드와 Rendering스레드 분리 예제 (0) | 2011.11.06 |
[android013] 비트맵 그리기 (0) | 2011.11.06 |
[android012] 캔바스 예제 - 도형 그리기 (0) | 2011.11.06 |
[android011] 캔바스 예제 - 랜덤 색상 배경화면 (0) | 2011.11.06 |