'Android'에 해당되는 글 16건

  1. 2010.09.30 [CustomAdapter]
  2. 2010.09.28 [MyHandlerTest]
  3. 2010.08.23 [ImageButton, Toast]
  4. 2010.08.19 [AlertDialog2]
  5. 2010.08.18 [AlertDialog]
  6. 2010.08.18 [MenuTest]
  7. 2010.08.17 [ImageView]
  8. 2010.08.17 [LifeCycle]
  9. 2010.08.16 [ShapeEx]
  10. 2010.08.16 [.java로 View Control]

[CustomAdapter]

|
커스텀뷰 xml 작성
<RelativeLayout>
<ImageView />
<TextView />
<Button />
</RelativeLayout>

리스트뷰 listtest.xml 작성
<LinearLayout>
<ListView />
</LinearLayout>

.java 작성
setContentView(R.layout.listtest)

ArrayList 생성
MyItem 생성하여 ArrayList에 추가
ArrayList를 커스텀어댑터에 붙임

CustomAdapter 클래스 정의
BaseAdapter 상속


CustomAdapter 객체 생성
MyListAdapter myAdapter = new MyListAdapter(this, R.layout.icontext, arItem);

ListView 생성
listtest.xml에서 listview를 가져옴
myList.setAdapter(myAdapter);

어댑터뷰에서 데이터를 가져오는 방법
객체에서 : new (this, customview_xml, data_instance)
xml에서 : createFromResource(this, data_xml, view_design)


-

'Android' 카테고리의 다른 글

[MyHandlerTest]  (0) 2010.09.28
[ImageButton, Toast]  (0) 2010.08.23
[AlertDialog2]  (0) 2010.08.19
[AlertDialog]  (0) 2010.08.18
[MenuTest]  (0) 2010.08.18
And

[MyHandlerTest]

|

MyHandlerTest.java
package net.itisn.com;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MyHandlerTest extends Activity {
	TextView increaseText;
	TextView decreaseText;
	Button startButton;
	
	/** Called when the activity is first created. */
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        increaseText = (TextView)this.findViewById(R.id.increase);
        decreaseText = (TextView)this.findViewById(R.id.decrease);
        startButton = (Button)this.findViewById(R.id.start);
        
        increaseText.setTextSize(30);
        decreaseText.setTextSize(30);
        startButton.setTextSize(30);
        
        startButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				new Thread(new IncreaseThread(updateHandler)).start();
		        new Thread(new DecreaseThread(updateHandler)).start();
			}
		});
    }
	
	class IncreaseThread extends Thread {
		Handler updateHandler;
		int increaseValue = 0;
		
		public IncreaseThread(Handler updateHandler) {
			this.updateHandler = updateHandler;
		}
		
		public void run() {
			// TODO Auto-generated method stub
			while (true) {
				increaseValue++;
				Message msg = Message.obtain();
				msg.what = 0;
				msg.arg1 = increaseValue;
				updateHandler.sendMessage(msg);
				try {
					sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	class DecreaseThread extends Thread {
		Handler updateHandler;
		int decreaseValue = 100;
		
		public DecreaseThread(Handler updateHandler) {
			this.updateHandler = updateHandler;
		}
		
		public void run() {
			// TODO Auto-generated method stub
			while (true) {
				decreaseValue--;
				Message msg = Message.obtain();
				msg.what = 1;
				msg.arg1 = decreaseValue;
				updateHandler.sendMessage(msg);
				try {
					sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	Handler updateHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			if (msg.what == 0) {
				increaseText.setText("Increase : " + msg.arg1);
			} else if (msg.what == 1) {
				decreaseText.setText("Decrease : " + msg.arg1);
			}
		}
		
	};
}


-

'Android' 카테고리의 다른 글

[CustomAdapter]  (0) 2010.09.30
[ImageButton, Toast]  (0) 2010.08.23
[AlertDialog2]  (0) 2010.08.19
[AlertDialog]  (0) 2010.08.18
[MenuTest]  (0) 2010.08.18
And

[ImageButton, Toast]

|

C++pasted just now: 
package net.itisn.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class FrameLayoutTest extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		ImageButton btn1 = (ImageButton) this.findViewById(R.id.ImageButton01);
		ImageButton btn2 = (ImageButton) this.findViewById(R.id.ImageButton02);
		ImageButton btn3 = (ImageButton) this.findViewById(R.id.ImageButton03);
		ImageButton btn4 = (ImageButton) this.findViewById(R.id.ImageButton04);

		btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(FrameLayoutTest.this, "Hi~~ north",
				        Toast.LENGTH_LONG).show();
			}
		});
	}
}


d
Haskellpasted 1 second ago: 
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
	android:id="@+id/FrameLayout01"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	xmlns:android="http://schemas.android.com/apk/res/android"
>
	<ImageButton
		android:id="@+id/ImageButton01"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_gravity="top|center"
		android:background="@drawable/su"
	></ImageButton>
	<ImageButton
		android:id="@+id/ImageButton02"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_gravity="left|center"
		android:src="@drawable/icon"
	></ImageButton>
	<ImageButton
		android:id="@+id/ImageButton03"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_gravity="right|center"
		android:src="@drawable/icon"
	></ImageButton>
	<ImageButton
		android:id="@+id/ImageButton04"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_gravity="bottom|center"
		android:src="@drawable/icon"
	></ImageButton>

</FrameLayout>


-

'Android' 카테고리의 다른 글

[CustomAdapter]  (0) 2010.09.30
[MyHandlerTest]  (0) 2010.09.28
[AlertDialog2]  (0) 2010.08.19
[AlertDialog]  (0) 2010.08.18
[MenuTest]  (0) 2010.08.18
And

[AlertDialog2]

|
AlertDialogTest2.java

setTitle() : 제목 설정
setMessage() : 아이콘 설정
setPositiveButton("text", listener) : 버튼 생성, listener를 null로 설정하면 버튼을 눌렀을 때 다이얼로그가 사라지며 아무 동작 안함.
listener를 인터페이스로 구현해 놓았으므로 DialogInterface.OnClickListener() 어댑터를 생성하여 onClick()을 오버라이딩하여 작성한다.
AlertDialogTest2.java
package net.itisn.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class AlertDialogTest2 extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button button = (Button) this.findViewById(R.id.Button01);
		button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder builder = new AlertDialog.Builder(
				        AlertDialogTest2.this);
				builder.setTitle("Notice");
				builder.setMessage("Dialog is opened. Congraturation!");
				builder.setIcon(R.drawable.icon);
				// builder.setPositiveButton("Close", null); // 닫는 버튼 생성
				builder.setPositiveButton("Close",
				        new DialogInterface.OnClickListener() {

					        @Override
					        public void onClick(DialogInterface dialog,
					                int which) {
						        // TODO Auto-generated method stub

					        }
				        });
				builder.show();
			}
		});
	}
}


-

'Android' 카테고리의 다른 글

[MyHandlerTest]  (0) 2010.09.28
[ImageButton, Toast]  (0) 2010.08.23
[AlertDialog]  (0) 2010.08.18
[MenuTest]  (0) 2010.08.18
[ImageView]  (0) 2010.08.17
And

[AlertDialog]

|

1. Dialog ID를 생성한다.
2. onCreateDialog(int id)를 오버라이드한다.
3. AlertDialog의 서브클래스 Builder로 builder를 생성해 다이얼로그를 설정한다.
4. AlertDialog로 alert를 생성해 builder.create()로 다이얼로그를 생성한다.
5. onCreate()에 showDialog()로 다이얼로그를 보이게 한다.
AlertDialogTest.java
package net.itisn.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class AlertDialogTest extends Activity {
    /** Called when the activity is first created. */
	static final int QUIT_ID = 0;
    
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        showDialog(QUIT_ID);
    }
    
	@Override
	protected Dialog onCreateDialog(int id) {
		// TODO Auto-generated method stub
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("Are you sure you want to exit")
		.setCancelable(false)
		.setPositiveButton("Yes",
			new DialogInterface.OnClickListener() {
					
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					AlertDialogTest.this.finish();
				}
			})
		.setNegativeButton("No",
			new DialogInterface.OnClickListener() {
					
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					dialog.cancel();
				}
			});
		AlertDialog alert = builder.create();
		
		//return super.onCreateDialog(id);
		return alert;
	}
}

-

'Android' 카테고리의 다른 글

[ImageButton, Toast]  (0) 2010.08.23
[AlertDialog2]  (0) 2010.08.19
[MenuTest]  (0) 2010.08.18
[ImageView]  (0) 2010.08.17
[LifeCycle]  (0) 2010.08.17
And

[MenuTest]

|

메뉴 생성하기
1. static final로 itemid를 만든다.
2. onCreateOptionMenu(Menu menu)를 오버라이드하여 menu.add()로 메뉴를 추가한다.
3. onOptionsItemSelected(MenuItem item)를 오버라이드하여 메뉴와 액션을 연결한다.

컨텍스트 메뉴 생성하기
1. static final로 itemid를 만든다.
2. onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo info)를 오버라이드하여 menu.add()로 메뉴를 추가한다.
3. onContextedItemSelected(MenuItem item)를 오버라이드하여 메뉴와 액션을 연결한다.
4. 메뉴를 출력하고자 하는 View의 아이디를 지정한다.
4. onCreate(Bundle savedInstanceState)에 registerForContextMenu(View view)로 컨텍스트 메뉴를 등록한다.

MenuTest.java
package net.itisn.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;

public class MenuTest extends Activity {
    /** Called when the activity is first created. */
	static final int MENU_NEW_GAME = 0;
	static final int MENU_QUIT = 1;
	static final int EDIT_ID = 2;
	static final int DELETE_ID = 3;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //기본 생성되는 TextView는 id가 없다. 따라서 id를 적어 주어야 한다.
        //@+id/TextView01
	registerForContextMenu(this.findViewById(R.id.TextView01));
    }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		menu.add(0, MENU_NEW_GAME, 0, "New Game");
		menu.add(0, MENU_QUIT, 0, "Quit").setIcon(R.drawable.icon);
		
		return super.onCreateOptionsMenu(menu); //equals to return true.
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch(item.getItemId()) {
		case MENU_NEW_GAME:
			//newGame();
			return true;
		case MENU_QUIT:
			//quit();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		// TODO Auto-generated method stub
		menu.add(0, EDIT_ID, 0, "Edit");
		menu.add(0, DELETE_ID, 0, "Delete");
		super.onCreateContextMenu(menu, v, menuInfo);
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
		switch (item.getItemId()) {
		case EDIT_ID:
			//editNote(Info.id);
			return true;
		case DELETE_ID:
			//deleteNote(Info.id);
		default:
			return super.onContextItemSelected(item);
		}
	}
	
}


-

'Android' 카테고리의 다른 글

[AlertDialog2]  (0) 2010.08.19
[AlertDialog]  (0) 2010.08.18
[ImageView]  (0) 2010.08.17
[LifeCycle]  (0) 2010.08.17
[ShapeEx]  (0) 2010.08.16
And

[ImageView]

|
1. ImageView.java 생성
2. View 클래스를 상속받은 클래스는 생성자가 반드시 있어야 하므로 ImageView(Context context) {...} 생성
3. 콘텍스트에서 리소스를 가져온다.
4. 가져온 리소스를 디코드한다.
5. onDraw()를 오버라이드하여 drawBitmap()으로 그림을 그린다.


ImageTest.java
C++pasted just now: 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package net.itisn.test;

import android.app.Activity;
import android.os.Bundle;

public class ImageTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        setContentView(new ImageView(this));
    }
}

ImageView.java
package net.itisn.test;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;

public class ImageView extends android.widget.ImageView {

	private Bitmap image;
	public ImageView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.setBackgroundColor(Color.WHITE);
		
		//그림 읽기
		Resources r = context.getResources();
		image = BitmapFactory.decodeResource(r, R.drawable.icon);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		canvas.drawBitmap(image, 0, 0, null);
		
		int w = image.getWidth();
		int h = image.getHeight();
		Rect src = new Rect(0, 0, w, h);
		Rect dst = new Rect(0, 70, w*3, h*3+70);
		canvas.drawBitmap(image, src, dst, null);
	}
}



-end

'Android' 카테고리의 다른 글

[AlertDialog]  (0) 2010.08.18
[MenuTest]  (0) 2010.08.18
[LifeCycle]  (0) 2010.08.17
[ShapeEx]  (0) 2010.08.16
[.java로 View Control]  (0) 2010.08.16
And

[LifeCycle]

|
인텐트 : 액티비티간 메시지 전달시 사용? 일종의 객체 직렬화??

TestLifeCycle.this.startActivity(intent);
객체를 생성하지 않았으므로 자신을 가리키기 위해서는 TestLifeCycle.this를 써야 한다.

Log는 Trace에서 사용
EJB에서도 Log 사용

소스코드가 바뀌면 일일이 수정 필요

스프링 프레임워크에서는 관점지향 프로그래밍을 사용 Aspect-Oriented Programming
Aspect-O...용 컴파일러도 있음 AspectJ
컴파일하면서 로그를 삽입해줌...CrossCut

Log filter

우측 상단 창+모양 클릭 > 디버그
로그캣 > + 클릭 > Name : TestLifeCycle, Tag : TestLIfeCycle 입력 > 디버그

1. 버튼을 가져온다.
2. 버튼에 클릭이벤트를 생성한다.
3. 클릭이벤트 메소드를 정의한다. 액션뷰 인텐트를 생성한다.
4. 오버라이딩한 메소드마다 로그를 남긴다.

Intent란?

LifeCycleTest.java
package net.itisn.test;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TestLifeCycle extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button button = (Button)this.findViewById(R.id.Button01);
		button.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				// TODO auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW,
					Uri.parse("http://www.google.com"));
				TestLifeCycle.this.startActivity(intent);
			}
		});
		Log.i("TestLifeCycle", "onCreate");
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Log.i("TestLifeCycle", "onDestroy");
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Log.i("TestLifeCycle", "onPause");
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		Log.i("TestLifeCycle", "onRestart");
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Log.i("TestLifeCycle", "onResume");
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Log.i("TestLifeCycle", "onStart");
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Log.i("TestLifeCycle", "onStop");
	}
}


-end


'Android' 카테고리의 다른 글

[MenuTest]  (0) 2010.08.18
[ImageView]  (0) 2010.08.17
[ShapeEx]  (0) 2010.08.16
[.java로 View Control]  (0) 2010.08.16
[RelativeLayout] 0. 레이아웃 만들기  (0) 2010.08.13
And

[ShapeEx]

|
#도형 그리기
ShapeView.java
1. drawText() 이용
2. moveTo(), lineTo() 이용
package net.itisn.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Paint.Style;
import android.view.View;

public class ShapeView extends View {

	public ShapeView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.setBackgroundColor(Color.WHITE);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		// 그리기 객체 생성
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		
		// 선 그리기
		paint.setStrokeWidth(20);	// 굵기
		paint.setStyle(Style.STROKE);	// 실선
		paint.setColor(Color.argb(255, 255, 0, 255));
		canvas.drawLine(0, 0, 200, 200, paint);
		
		// Path를 이용한 그리기
		paint.setStrokeWidth(10);	// 굵기
		paint.setStyle(Style.STROKE);
		paint.setColor(Color.argb(255, 0, 255, 255));
		Path path = new Path();
		path.moveTo(255, 210);
		path.lineTo(0, 0);
		canvas.drawPath(path, paint);
		
		
		
	}
}


도형 그리기
package net.itisn.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.view.View;

public class ShapeView extends View {

	public ShapeView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.setBackgroundColor(Color.WHITE);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		// 그리기 객체 생성
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		
		// 선 그리기
		paint.setStrokeWidth(20);	// 굵기
		paint.setStyle(Style.STROKE);	// 실선
		paint.setColor(Color.argb(255, 255, 0, 255));
		canvas.drawLine(0, 0, 200, 200, paint);
		
		// Path를 이용한 선 그리기
		paint.setStrokeWidth(10);
		paint.setStyle(Style.STROKE);
		paint.setColor(Color.argb(255, 0, 255, 255));
		Path path = new Path();
		path.moveTo(255, 210);
		path.lineTo(0, 0);
		canvas.drawPath(path, paint);
		
		// 사각형 그리기
		paint.setColor(Color.BLUE);
		paint.setStrokeWidth(2);
		canvas.drawRect(new Rect(100, 100, 200, 200), paint);
		canvas.drawRect(300, 20, 10, 500, paint);
		
		// 라운드 사각형 그리기
		paint.setColor(Color.argb(255, 255, 0, 255));
		canvas.drawRoundRect(new RectF(10, 10, 100, 100), 10, 10, paint);
		
		// 원 그리기
		canvas.drawCircle(50, 50, 40, paint);
	}
}



-end

'Android' 카테고리의 다른 글

[ImageView]  (0) 2010.08.17
[LifeCycle]  (0) 2010.08.17
[.java로 View Control]  (0) 2010.08.16
[RelativeLayout] 0. 레이아웃 만들기  (0) 2010.08.13
XML 문법  (0) 2010.08.13
And

[.java로 View Control]

|
#자바 파일로 작성

StringEx extends Activity {
setContentView(new StringView(this));
StringView라는 클래스의 객체를 생성하여 StringEx를 넘겨준다.
그러면 StringView는 StringEx를 받아 거기에 그림을 그리거나 글을 쓴다.
StringView는 그림을 그리거나 글을 쓸 때 onDraw()가 필요하기 때문에 View를 상속받는다.
super.onDraw(canvas);를 가장 먼저 실행한 후, 원하는 작업 수행

1. onCreate
2. onStart
3. onResume
4. setContentView(new StringView(this));

StringEx.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package net.itisn.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class StringEx extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(new StringView(this));
    }
}


StringView.java
package net.itisn.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class StringView extends View {

	public StringView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.setBackgroundColor(Color.WHITE);
	}

	//그리기 함수
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		//그리기 객체
		Paint paint = new Paint();
		paint.setAntiAlias(true);	//그리기 객체에 안티알리아스 적용

		//문자 크기 및 색상 설정
		paint.setTextSize(12);
		paint.setColor(Color.argb(255, 0, 0, 0));

		//폰 화면 가져와서 글자 쓰기
		canvas.drawText("화면 넓이" + this.getWidth() + 
				"화면 높이" + this.getHeight(),
				0, 30, paint);
		
		//문자열의 폭 구하기
		canvas.drawText("문자열 폭" + (int)paint.ascent(), 0, 60, paint);
		
		//문자 크기 16, 색상 빨간색 설정
		paint.setTextSize(16);
		paint.setColor(Color.argb(128, 255, 0, 0));
		
		//폰 화면(canvas)에 그리기
		canvas.drawText("두번째 문자", 0, 90, paint);
		
	}
}

'Android' 카테고리의 다른 글

[LifeCycle]  (0) 2010.08.17
[ShapeEx]  (0) 2010.08.16
[RelativeLayout] 0. 레이아웃 만들기  (0) 2010.08.13
XML 문법  (0) 2010.08.13
[CustomView] 4. Thread 이용하여 그림 움직이기  (0) 2010.08.12
And
prev | 1 | 2 | next