473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Drawing on Canvas in Android

I'm trying to draw a rectangle on a canvas in my own View:
Expand|Select|Wrap|Line Numbers
  1. public class CustomMainMenuDrawView extends View {
  2.     Paint paint = new Paint();
  3.  
  4.     public CustomMainMenuDrawView(Context context) {
  5.         super(context);
  6.         paint.setColor(Color.BLACK);
  7.     }
  8.  
  9.     @Override
  10.     public void onDraw(Canvas canvas) {
  11.             paint.setColor(color.black);
  12.             Rect r = new Rect();
  13.             r.set(40, 30, 80, 100);
  14.             canvas.drawRect(r, paint);
  15.     }
  16.  
  17. }
  18.  
and add the view to my own activity:
Expand|Select|Wrap|Line Numbers
  1. public class MainActivity extends Activity {
  2.     CustomMainMenuDrawView draw;
  3.     @Override
  4.     protected void onCreate(Bundle savedInstanceState) {
  5.         super.onCreate(savedInstanceState);
  6.  
  7.         draw = new CustomMainMenuDrawView(this);
  8.         draw.setBackgroundColor(Color.RED);
  9.  
  10.  
  11.     }
  12.  
which works for setting a background color; however, it does not work when drawing an image. I am forcing the app to be in landscape mode and don't know if this could be having an affect. Can someone give me some advice on how to draw a shape in android? Am I suppose to use the XML file or no?

Thanks,
CodeNoob117
Nov 11 '13 #1
0 1676

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Karen Easley | last post by:
Hi Suppose you have a canvas which allows users t create object dynamically; e.g. lines, boxes, etc If you would like the user to be able 1) to select one of these object 2) give it the...
2
by: billy | last post by:
I'm working on a sort of paint program that has the usual canvas pane in the middle of the main form. I'm working on that class and have a couple quick questions.. actually more like I'm looking...
0
by: the dark lord | last post by:
Greetings I wish someone can offer me some suggestions to optimize my code: I have a drawing surface and I wanted to create a pair of rulers for it like in popular image editing programs like...
7
by: Pontifex | last post by:
Hi all, I heard or read that the next version of HTML will provide long-overdue drawing commands. Which version of Firefox, Opera or IE supports such new fancy stuff? Thanks!
2
by: Rex the Strange | last post by:
I suspect the answer to this question is "you can't," but here goes anyway: I have a tabcontrol which contains, of course, various tabpages (added programmatically at runtime, but this is...
5
by: Andrew Poulos | last post by:
Is there a right/best way to draw an ellipse using Canvas? (With VML there's the v:oval element which makes the exercise trivial). I tried drawing a 360 degree arc (a circle) and then scaling it...
1
by: Andrew | last post by:
Hello Everyone I am receiving an error in an application I am working on. The application when its done will be a Dungeons and Dragons Network game. I am having problems with the Networked...
15
by: javelin | last post by:
I need to be able to create a javascript based drawing/signature box, and be able to save it. Can someone refer me to a script that will allow this, or even a 3rd party package for sale? It can't...
7
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the...
1
by: game2d | last post by:
i am trying to make a templet for making android games. this is what i have so far. two classes. one does the animation and other touch listener. If there is some thing better PLZ let me know so i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.