Extreme beginner. using shapeDrawable. help please

Put your problem here if it does not fit any of the other categories.

Extreme beginner. using shapeDrawable. help please

Postby thapickle » Fri Dec 04, 2009 8:34 am

Ok. So I am really a beginner to Java and Android so please don't flame.
I am trying to eventually build up to making a pong clone so I have been reading tutorials.
Trying to just draw a rectangle using shapeDrawable. Here is my code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package sc.android.game;
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.content.Context;
  9.  
  10. import android.graphics.*;
  11.  
  12. import android.graphics.drawable.ShapeDrawable;
  13.  
  14. import android.os.Bundle;
  15.  
  16. import android.view.View;
  17.  
  18. import android.view.Window;
  19.  
  20. import android.widget.*;
  21.  
  22.  
  23.  
  24. public class Game extends Activity {
  25.  
  26.     /** Called when the activity is first created. */
  27.  
  28.     @Override
  29.  
  30.     public void onCreate(Bundle savedInstanceState) {
  31.  
  32.         super.onCreate(savedInstanceState);
  33.  
  34.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  35.  
  36.         setContentView(new Panel(this));
  37.  
  38.     }
  39.  
  40.    
  41.  
  42.     class Panel extends View
  43.  
  44.     {
  45.  
  46.        
  47.  
  48.         ShapeDrawable rect;
  49.  
  50.        
  51.  
  52.  
  53.  
  54.        
  55.  
  56.        
  57.  
  58.         public Panel(Context a)
  59.  
  60.         {
  61.  
  62.                 super(a);
  63.  
  64.                 rect = new ShapeDrawable();
  65.  
  66.                 rect.getPaint().setColor(Color.BLUE);
  67.  
  68.                 rect.setBounds(1,1, 10, 10);
  69.  
  70.         }
  71.  
  72.        
  73.  
  74.         public void onDraw(Canvas canvas)
  75.  
  76.         {
  77.  
  78.        
  79.  
  80.                
  81.  
  82.                
  83.  
  84.                 canvas.drawColor(Color.BLACK);
  85.  
  86.                 rect.draw(canvas);
  87.  
  88.                
  89.  
  90.    
  91.  
  92.                
  93.  
  94.         }
  95.  
  96.        
  97.  
  98.     }
  99.  
  100.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


My problem is
1. I dont understand fully what the parameters in setBounds(); do. It says Left Right Top Bottom. But i dont get it. Maybe I dont understand the coordinate system but can someone school me please. I really just want to know how exactly do I size it and place it at a certain position in the screens coordinate system. (which i dont know what is used.) I assume the top left corner is 1,1. first 1 gets bigger as you go right and second 1 gets bigger as you go down..(x and y). Is this right. Is there another method that sets the size and location that I use?Can someone school me on this please.
thapickle
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Dec 04, 2009 8:14 am
Location: San Francisco, CA

Top

Postby qlimax » Sun Dec 06, 2009 12:52 am

left The X coordinate of the left side of the rectagle
top The Y coordinate of the top of the rectangle
right The X coordinate of the right side of the rectagle
bottom The Y coordinate of the bottom of the rectangle

you must ensure that left <= right and top <= bottom

get it ?

bye :wink:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 26 guests