activity_main.xml
Fayl: activity_main.xml
< RelativeLayout xmlns:androclass = "http://schemas.android.com/apk/res/android" xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent" android:layout_height = "match_parent" android:paddingBottom = "@dimen/activity_vertical_margin" android:paddingLeft = "@dimen/activity_horizontal_margin"
android:paddingRight = "@dimen/activity_horizontal_margin" android:paddingTop = "@dimen/activity_vertical_margin" asboblar: kontekst = ".MainActivity" >
< TextView
android:layout_width = "wrap_content" android:layout_height = "wrap_content" android: matn = "@string/hello_world" />
RelativeLayout >
Faoliyat klassi
com.example.simplegraphics paketi ;
android.os.Bundle import ; android.app.Activity import ; android.view.Menu import ; android.content.Context import ; import android.graphics.Canvas; android.graphics.Color import ; android.graphics.Paint import ; android.view.View import ;
umumiy sinf MainActivity faollikni kengaytiradi {
DemoView namoyishi;
/** Faoliyat birinchi marta yaratilganda chaqiriladi. */ @Override
public void onCreate (to'plam savedInstanceState) {
super .onCreate(savedInstanceState); demoview = yangi DemoView( bu ); setContentView(namoyish);
}
xususiy sinf DemoView ko'rishni kengaytiradi {
umumiy DemoView (kontekst konteksti){
super (kontekst);
}
@Override himoyalangan bekor onDraw(Canvas canvas) {
super .onDraw(kanvas);
// bu yerda maxsus chizma kodi Paint bo'yoq = new Paint(); paint.setStyle(Paint.Style.FILL);
// butun tuvalni oq rangga aylantiring paint.setColor(Color.WHITE); canvas.drawPaint(bo'yoq);
// anti aliasing o'chirilgan holda ko'k doira chizish paint.setAntiAlias( false ); paint.setColor(Color.BLUE);
canvas.drawCircle( 20 , 20 , 15 , bo'yoq);
// anti aliasing yoqilgan yashil doira chizing paint.setAntiAlias( rost ); paint.setColor(Color.GREEN); canvas.drawCircle( 60 , 20 , 15 , boʻyoq);
// anti aliasing o'chirilgan holda qizil to'rtburchak chizish paint.setAntiAlias( false );
paint.setColor(Color.RED);
canvas.drawRect( 100 , 5 , 200 , 30 , boʻyoq);
// aylantirilgan matnni chizish canvas.rotate(- 45 );
paint.setStyle(Paint.Style.FILL);
canvas.drawText( "Grafikani aylantirish" , 40 , 180 , bo'yoq);
// aylantirishni bekor qilish canvas.restore();
}
}
@Override
Dostları ilə paylaş: |