Results 1 to 2 of 2
  1. #1
    learning.java is offline Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0

    Default Android Paths / Canvas / View /

    Hello, I am trying to make a simple Android "app" that moves across the screen with one touch.

    - My main Activity is CarActivity


    - I wrote a Car class with constructer that take in (int x, int, int
    color)

    -I created a CarView class which I made a instance of a car.


    -I'm TRYING to make a moveCar method that takes ina new X
    and Y coordinate and assings them to the Car. using refrence points from (Car.getx()) and use path variables for each of the draing compments and add path methods to form my drawing.

    - I NEED to make a onDraw method that take in a canvas object and use Canvas.drawPath to draw my object.

    Please help! here is my code so far. Thanks.


    Java Code:
    public class CarActvity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState)
    	{
    		super.onCreate(savedInstanceState);
    		CarView cv = new CarView(this);
    		setContentView(cv);
    	
    	}
    	
    	static public class Car
    	
    	{
    		private int x;
    		private int y;
    		private int color;
    		
    		public Car(int x, int y, int color)
    		{
    			super();
    			this.x = x;
    			this.y = y;
    			this.color = color;
    		}
    
    		/**
    		 * @return the x
    		 */
    		public int getX() 
    		{
    			return x;
    		}
    
    		/**
    		 * @param x the x to set
    		 */
    		public void setX(int x)
    		{
    			this.x = x;
    		}
    
    		/**
    		 * @return the y
    		 */
    		public int getY() 
    		{
    			return y;
    		}
    
    		/**
    		 * @param y the y to set
    		 */
    		public void setY(int y) 
    		{
    			this.y = y;
    		}
    
    		/**
    		 * @return the color
    		 */
    		public int getColor()
    		{
    			return color;
    		}
    
    		/**
    		 * @param color the color to set
    		 */
    		public void setColor(int color) 
    		{
    			this.color = color;
    		}
    		
    		
    	}
    	
    	static public class CarView extends View
    	{
    
    		public CarView(Context context)
    		{
    			super(context);
    			Car car = new Car(0, 0, 0);
    			
    			
    			
    			// TODO Auto-generated constructor stub
    		}
    		
    		static public void moveCar(int x2, int y2)
    		{
    			int x = x2;
    			int y = y2;
    			
    		}
    		
    		@Override
    		protected void onDraw(Canvas canvas)
    		{
    			super.onDraw(canvas);
    		
    		}
    		
    	}
    	
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.car_actvity, menu);
    		return true;
    	}
    
    }

  2. #2
    Kris3579 is offline Member
    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Default Re: Android Paths / Canvas / View /

    Please provide a theoretic image of the path.

Similar Threads

  1. Android Web View
    By baggio90 in forum Android
    Replies: 0
    Last Post: 12-08-2012, 09:51 PM
  2. startActivity error for Android graph view
    By bdtuhin007 in forum Android
    Replies: 2
    Last Post: 01-17-2012, 04:29 AM
  3. How enter this mode-gui/design-view/code-view
    By lse123 in forum NetBeans
    Replies: 0
    Last Post: 02-28-2010, 10:09 PM
  4. Replies: 0
    Last Post: 07-05-2009, 01:31 PM
  5. Updating a view using actions in a seperate view
    By xcallmejudasx in forum Eclipse
    Replies: 0
    Last Post: 10-24-2008, 10:24 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •