Android Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsMobile ProgrammingAndroid Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 27th, 2012, 05:01 AM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 122 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 59 m 35 sec
Reputation Power: 9
Calling setBackgroundDrawable() in a view class makes a infinite call loop to draw.

Hi Guys.

I'm relativly new the Android development, all though quite experienced with Java. I'm trying to make a background gradient, and so far succesfully using the following code in my onDraw method in my view class:

Code:
protected void onDraw(Canvas canvas)
	{
		
		Log.v("HelloWorld", "Drawing gradiant");
		int colors[] = new int[4];
		colors[0] = Color.GREEN;
		colors[1] = Color.rgb(128, 255, 128);
		colors[2] = Color.rgb(200, 255, 200);
		colors[3] = Color.WHITE;
		GradientDrawable gradiantBackColor = new GradientDrawable(Orientation.TL_BR, colors);
	
		setBackgroundDrawable(gradiantBackColor);
		setBackgroundColor(Color.GREEN);
	}

This makes a nice gradient green color from top to bottom. But i usually look through my LogCat to see if everything is called as it should, and i noticed that the onDraw method is being called ALOT, and it seems that the program is stuck in a refresh GFX loop. This also happens when i use the setBackgroundColor(color).

If I use the canvas.drawPaint() method, to make my background just green, the onDraw method is only called once. What gives?

I have tried to find an explanation to this loop behavior but so far come up short. Any have an explanation to this. I'm sort of certain i'm doing something wrong.

Btw, I'm debugging on an actual device: HTC Desire.

Here is a short copy paste of my log cat:
01-27 11:59:49.666: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.686: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.706: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.716: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.736: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.756: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.766: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.786: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.796: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.816: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.826: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.846: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.866: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.876: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.896: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.916: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.926: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.946: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.966: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.976: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:49.996: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:50.016: VERBOSE/HelloWorld(12398): Drawing gradiant
01-27 11:59:50.026: VERBOSE/HelloWorld(12398): Drawing gradiant

Reply With Quote
  #2  
Old March 13th, 2012, 05:09 AM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 122 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 59 m 35 sec
Reputation Power: 9
I found out what went wrong.

setBackgroundDrawable sets the UI state to invalid. This forces the activity to redraw, which means to called the ondraw method, that then calls setBackgroundDrawable, which then again sets the UI to invalid.

setting the setBackgroundDrawable the activity's on create fixed this problem.

Reply With Quote
Reply

Viewing: Dev Shed ForumsMobile ProgrammingAndroid Development > Calling setBackgroundDrawable() in a view class makes a infinite call loop to draw.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap