Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Graphics app in android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 81
    Comment on it

    Here I have created graphic app. In below example I have used android.graphics.Canvas. The android.graphics.Canvas provides method to draw oval,rectangle,text,picture etc.And The android.graphics.paint holds the information of color and style. Below example will described you how to make Graphics app.

    Step(1)- activity_main.xml Layout-

    <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"  
        tools:context=".MainActivity" >  
    
        <TextView  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Welcome Evon" />  
    
    </RelativeLayout>  
    

    Step(2)-MainActivity-

     public class MainActivity extends Activity {  
    
        RajView rajview;  
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            rajview = new RajView(this);  
            setContentView(rajview);  
        }  
    
        private class RajView extends View{  
            public RajView(Context context){  
                super(context);  
            }  
    
            @Override protected void onDraw(Canvas canvas) {  
                super.onDraw(canvas);  
    
                Paint paint = new Paint();  
                paint.setStyle(Paint.Style.FILL);  
    
                paint.setColor(Color.WHITE);  
                canvas.drawPaint(paint);  
    
                paint.setAntiAlias(false);  
                paint.setColor(Color.BLUE);  
                canvas.drawCircle(20, 20, 15, paint);  
    
                paint.setAntiAlias(true);  
                paint.setColor(Color.GREEN);  
                canvas.drawCircle(60, 20, 15, paint);  
    
                paint.setAntiAlias(false);  
                paint.setColor(Color.RED);  
                canvas.drawRect(100, 5, 200, 30, paint);  
    
                canvas.rotate(-45);  
    
                paint.setStyle(Paint.Style.FILL);  
                canvas.drawText("Graphics Rotation", 40, 180, paint);  
    
                canvas.restore();  
            }  
        }  
        @Override  
        public boolean onCreateOptionsMenu(Menu menu) {    
            getMenuInflater().inflate(R.menu.main, menu);  
            return true;  
        }  
    }  
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: