Graphic 2D 3D with OpenGL

104 152 1
Graphic 2D 3D with OpenGL

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

안드로이드 애플리케이션 교육 자료 – 7 Graphics, 2D and 3D with OpenGL www.kandroid.org 관리자 : 양정수 (yangjeongsoo@gmail.com), 닉네임:들풀 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:kandroid="http://schemas.android.com/apk/res/org.kandroid.testApp" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent” > <org.kandroid.testApp.CustomView android:background="@drawable/red" android:layout_width="fill_parent" android:layout_height="wrap_content" kandroid:text="Red"/> <org.kandroid.testApp.CustomView android:background="@drawable/blue" android:layout_width="fill_parent" android:layout_height="wrap_content" kandroid:text="Blue" kandroid:textSize="20dp"/> <org.kandroid.testApp.CustomView android:background="@drawable / green" android:layout_width="fill_parent" android:layout_height="wrap_content" kandroid:text="Green" kandroid:textColor="#ffffffff" /> /Li L 2Korea Android Community- www.kandroid.org < /Li near L ayout> public class MyView extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } public class CustomView extends View { public CustomView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomView(Context context, A ttributeSet attrs) { super(context, attrs); } public CustomView(Context context) { super(context); } } 3Korea Android Community- www.kandroid.org 4Korea Android Community- www.kandroid.org @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight ( heightMeasureSpec )); measureHeight ( heightMeasureSpec )); } private int measureHeight(int measureSpec) { int result = 0; int specMode = MeasureSpec getMode ( measureSpec ); int specMode = MeasureSpec . getMode ( measureSpec ); int specSize = MeasureSpec.getSize(measureSpec); mAscent = (int) mTextPaint.ascent(); if (specMode == MeasureSpec.EXACTLY) { result = specSize ; result = specSize ; } else { result = (int) (-mAscent + mTextPaint.descent()) + getPaddingTop() + getPaddingBottom(); if (specMode == MeasureSpec.AT_MOST) { result = Math min(result specSize ); result = Math . min(result , specSize ); } } return result; } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas drawText ( mText getPaddingLeft () getPaddingTop () mAscent mTextPaint ); 5Korea Android Community- www.kandroid.org canvas . drawText ( mText , getPaddingLeft () , getPaddingTop () - mAscent , mTextPaint ); } 6Korea Android Community- www.kandroid.org <?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?> <jardesc> <j th "D /D l t/P j t /A d id/M Vi j "/> <j ar pa th = "D : /D eve l opmen t/P ro j ec t s /A n d ro id/M y Vi ew. j ar "/> <options buildIfNeeded="true" compress="true" descriptionLocation="/MyView/MyView.jardesc“ exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="false“ saveDescription="true" storeRefactorings="false" useSourceFolders="false"/> < tdRfti dtiIf "t " ttlOl "f l "/> < s t ore dR e f ac t or i ngs d epreca ti on I n f o= "t rue " s t ruc t ura lO n l y= "f a l se "/> <selectedProjects/> <manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true"> <sealing sealJar "false"> <sealing sealJar = "false"> <packagesToSeal/> <packagesToUnSeal/> </sealing> </manifest> </manifest> <selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false"> <javaElement handleIdentifier="=MyView/src&lt;org.kandroid.testApp{MyView.java"/> <javaElement handleIdentifier="=MyView/src&lt;org.kandroid.testApp{CustomView.java"/> < javaElement handleIdentifier ="= MyView / src&lt;org kandroid testApp {R java"/> < javaElement handleIdentifier ="= MyView / src&lt;org . kandroid . testApp {R . java"/> </selectedElements> <fatjar builder="org.eclipse.jdt.ui.plain_jar_builder" launchConfig=""/> </jardesc> 7Korea Android Community- www.kandroid.org External Library 사용 8Korea Android Community- www.kandroid.org 9Korea Android Community- www.kandroid.org 1. Graphics 2. 2D Gra p hics p 3. 3D with OpenGL 3. 3D with OpenGL [...]...Graphics Overview Android graphics are powered by a custom 2D graphics library and OpenGL ES 1.0 for high performance 3D graphics The most common 2D graphics APIs can be found in the drawable package OpenGL APIs are available from the Khronos OpenGL ES package, plus some Android OpenGL utilities O GL tiliti When starting a project, it's important to consider exactly what your graphical demands... Community- www.kandroid.org 19 1 Graphics 2 2D Graphics p 3 3D with OpenGL 2D Graphics Overview Android offers a custom 2D graphics library for drawing and animating shapes and images The android.graphics.drawable and android.view.animation packages are where you'll find the common classes used for drawing and animating in two-dimensions This document offers an introduction to drawing graphics in your Android... looking for information on drawing 3D graphics, this page won't help a lot However, the information below, on Drawing with a Canvas (and the section on SurfaceView), will give you a quick idea of how you should draw to the View hierarchy For more information on hierarchy Android's 3D graphic utilities (provided by the OpenGL ES API), read 3D with OpenGL and refer to other OpenGL documentation Korea Android... www.kandroid.org 11 Graphics Consider your options When drawing 2D graphics, you'll typically do so in one of two ways: a b Draw your graphics or animations into a View object from your layout In this manner, the drawing (and any animation) of your graphics is handled by the system's normal View hierarchy drawing process - you simply define the graphics to go inside the View Draw your graphics directly... second) with: transition.startTransition(1000); Refer to the Drawable classes listed above for more information on the XML attributes supported by each Korea Android Community- www.kandroid.org 29 2D Graphics Korea Android Community- www.kandroid.org 30 2D Graphics ShapeDrawable When you want to dynamically draw some two-dimensional graphics, a ShapeDrawable object will probably suit your needs With a... demands will be Varying graphical tasks are best accomplished with varying techniques For example, graphics and animations f a rather static application should b i l d i ti for th t ti li ti h ld be implemented much diff t d h differently th tl than graphics and animations for an interactive game or 3D rendering Here, we'll discuss a few of the options you have for drawing graphics on Android, and... Community- www.kandroid.org 12 Graphics Simple Graphics Inside a View If you'll be drawing some simple graphics (images, shapes, colors, pre-defined animations, etc.), then you should probably just draw to the background of a View or to the content of an ImageView in your layout In this case, you can skip the rest of this document and learn how to draw graphics and animations in the 2D Graphics document Korea... drawing to a View, is your best choice when you want to draw simple graphics that do not need to change dynamically and are not part of a performance-intensive game For example, you should draw your graphics into a View when you want to display a static graphic or predefined animation, within an otherwise static application Read Simple Graphics Inside a View Option "b," drawing to a Canvas, is better... Android application We'll discuss the basics of using Drawable objects to draw graphics, how to use a couple subclasses of the Drawable class, and how to create animations that either tween (move, stretch, rotate) a single graphic or animate a series of graphics (like a roll of film) Korea Android Community- www.kandroid.org 21 2D Graphics Drawables A Drawable is a general abstraction for "something that... layout ( (with some red tint just for fun) j ) For more information on using p j g project resources, read about Resources and Assets , Korea Android Community- www.kandroid.org 26 2D Graphics Korea Android Community- www.kandroid.org 27 2D Graphics Drawables . xmlns :android= "http://schemas .android. com/apk/res /android& quot; xmlns:kandroid="http://schemas .android. com/apk/res/org.kandroid.testApp" android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="fill_parent”. > <org.kandroid.testApp.CustomView android: background="@drawable/red" android: layout_width="fill_parent" android: layout_height="wrap_content" kandroid:text="Red"/>. kandroid:text="Red"/> <org.kandroid.testApp.CustomView android: background="@drawable/blue" android: layout_width="fill_parent" android: layout_height="wrap_content" kandroid:text="Blue"

Ngày đăng: 28/04/2014, 15:48

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan