오늘은 커스텀 뷰를 만들고 Bitmap을 리소스로 부터 불러와서 표시합니다.

activity를 생성하고 layout에 커스텀 뷰를 설정하고 클래스를 만듭니다.

resource xml 설정

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 		android:orientation="vertical"
 		android:layout_width="fill_parent"
 		android:layout_height="fill_parent"
 	>
<com.shin.view.CustomView
    android:id="@+id/custom_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />
</LinearLayout>


CustomView를 Xml 파일에 입력을 했다면 변수가 필요합니다.

public CustomView(Context context,AttributeSet attrs)


bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ex1 );

이렇게 설정을하고 클래스 파일에서 리소스로 부터 Bitmap을 불러옵니다.


public CustomView(Context context,AttributeSet attrs) {
        super(context, attrs);
        orign = new Rect();
        dest = new Rect();
        
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ex1 );
        orign.left = 0;
        orign.right = bitmap.getWidth();
        orign.top = 0;
        orign.bottom = bitmap.getHeight();
        
        paint = new Paint();
        
	}

리소스파일

결과 화면

결과파일


ShinExample_06.zip



Posted by App.SHIN
:

BLOG main image
by App.SHIN

공지사항

카테고리

분류 전체보기 (27)
안드로이드 (12)
추천앱 (0)
맛집 (0)
영화 (0)
핫이슈 (2)
서버 (2)
mac os 적응기 (8)
java (1)
mysql (1)
tomcat (1)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

달력

«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Total :
Today : Yesterday :