Painting a background on a MainScreen
There is a thread with quite a few posts about this and I posted a solution there but it gets cumbersome trying to find the information.
I've posted it here again for easy reference. How to create a MainScreen with a custom background, preserving scrolling and avoiding the use of padding field hacks: Code:
class ExtendedCustomMainScreen extends CustomMainScreen { |
Thanks a lot for this wondefull and helpfull post.
On the other topic I found a lot of explanation but it's a good idea to post a resume here. Very good work and thanks again Edit => Arff I spoke too fast. In fact when I use your customMainScreen and make my application extends it nothing appear. For example my first screen display a picture Code:
//invoke the MainScreen constructor My menuItems are present but not the picture. I have only a white screen REdit => Maybe I should implement delete() and deleteAll() as you implement add()?? Edit again=> So when I implement delete() and deleteAll() it works fine for the first screen. But my program call other function and the background hasn't the color and fields don't appear. In fact I use only one screen and I delete what I want and replace by new field to make my new screen. Why the CustomMainScreen isn't used?? And how can I tell the program to keep it?? |
No answer???
|
getBitmapResource is a static method, so you don't have to create a Bitmap object to use it. I'm only recently getting back into java coding, so I'm very rusty on variable scope and garbage collection, but you're passing an object to BitmapField that you do not keep in scope, so perhaps it is being destroyed by the GC?
Instead of this: bmp = new Bitmap(taillehorizon , taillevertical); picture = new BitmapField(bmp.getBitmapResource("Accueil.png")); Do this: bmp = Bitmap.getBitmapResource("Accueil.png"); picture = new BitmapField(bmp); And make sure bmp is static or a member of your class. |
Hum thanks for your answer but I think you have missunderstanding me.
I don't have any problem in displaying a picture. The problem come from the background color. I can change it only for the consctructor of my screen but when I call another function wich repaint all the screen I loose the color and I can't display anything on the screen |
When I call invalidate on the screen, add and remove fields etc., it seems to work fine. Can you explain further? I'm not sure I understand.
|
Allright a quick exemple is better :
Code:
class MainScreenWithBackgroundMain extends UiApplication So two questions. Why my screen become white and no fields are added?? And how can I keep the backgroung color when calling next?? |
|
I read it already but when I read it again I understand some thing.
So correct me if I'm wrong but for each fonction I have to create a vertical manager with the properties I want and add it. It's not so difficult so is it??? |
Allright don't mind with it.
I found my solution. Simply declare a verticalfield manager and add it to the screen and the I add fields to it. Thanks for the time you spent on my problem |
Hum I speak too fast.
In fact I haven't problem when the verticalField is larger thant the screen but when it's smaller the background color just take it's size and not the whole screen. How can I change this??? |
untested, by mreed over at the supportforums:
Code:
protected void paint( Graphics graphics ) { |
No change with this. I paint only the background but not the entire screen
The problem come from that the verticalField hasn't the size of the screen. When biggest no problem but when smallest... |
I edited the original post. It should fix your issue.
Couple comments: You can't use the code simon references because the mainscreen does not paint past the display length (i.e. not the length of its delegate). The only solution is to control the behavior of the delegate itself. However, you can't do that either so the next best thing is to make the delegate non-scrollable and then add a scrollable VerticalFieldManager to the delegate and ensure it is at least as big as the display. I did employ simon's technique in paintBackground as it is a little faster. |
Really good job.
It's works very fine. Thanks a lot for your helpfull answer |
Everything works great...except...it seems that I cannot get anything aligned in the center (i.e. ...new VerticalFieldManager(VerticalFieldManager.FIELD_HC ENTER).
Seems like everything aligns from the left. When i remove the painted background screen subclass, it works fine. |
nyteek,
Could you post a code example of what you're trying to accomplish? |
Quote:
Code:
public class PaintedBackgroundScreen extends MainScreen{ Code:
public class AppMainScreen extends PaintedBackgroundScreen{ |
I'm thinking:
Is it possible by using the same method to use a picture in background??? |
Quote:
in your paintBackground() method you would have something like the following... Code:
g.clear(); |
All times are GMT -5. The time now is 08:00 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.