Hi,
I have same problem. Please help me to solved out this.
I am trying to implement scrolling functionality in Blackberry Strom application. I have to display one image which height is 500. But I have to display it in Vertical field manager with height 436 only. And I have to implement scroll feature to display that image within this layout. Strom has total display height is 480. But I have to place horizontal field below this main Vertical Field. Following is example code. Please guid me to solve this issue.
This is main class file MainLite.java
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.TouchGesture;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class MainLite extends UiApplication //implements FieldChangeListener
{
public static void main(String[] args)
{
//create a new instance of the application
//and start the application on the event thread
MainLitetheApp = new MainLite();
theApp.enterEventDispatcher();
}
public MainLite()
{
//display a new screen
pushScreen(new MainScreenLite());
}
}
class MainScreenLite extends MainScreen implements FieldChangeListener
{
//VerticalFieldManager vfmHanuman0 = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | VerticalFieldManager.VERTICAL_SCROLL |VerticalFieldManager.USE_ALL_WIDTH |VerticalFieldManager.FIELD_HCENTER | DEFAULT_CLOSE);
Manager mainMgr = new VerticalFieldManager();
HorizontalFieldManager hfmNavigation = new HorizontalFieldManager();
VerticalFieldManager vfmleft = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
VerticalFieldManager vfmMiddle = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
VerticalFieldManager vfmright = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
String Image;
drawimage mainscreenimage;
previousnext Previous;
previousnext Next;
middle Middle;
public MainScreenLite() {
super();
try
{
Image="2.PNG";
mainscreenimage = new drawimage(Image,Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | DEFAULT_MENU | DEFAULT_CLOSE |UPWARD );
mainMgr.add(mainscreenimage);
mainMgr.add(new NullField(Field.FOCUSABLE));
add(mainMgr);
}
catch (Exception e)
{
}
// Put Navigation Buttons and Events On Field Manager
Previous = new previousnext("About",Field.FOCUSABLE);
Previous.setChangeListener(this);
vfmleft.add(Previous);
Middle = new middle("Middle",Field.FOCUSABLE);
//Middle.setChangeListener(this);
vfmMiddle.add(Middle);
Next = new previousnext("Next",Field.FOCUSABLE);
Next.setChangeListener(this);
vfmright.add(Next);
hfmNavigation.add(vfmleft);
hfmNavigation.add(vfmMiddle);
hfmNavigation.add(vfmright);
add(hfmNavigation);
}
}
So I want to display Image name 2.PNG on Top (with vertical field manager, height is 436 for vertical field manager and image height is 500) and Next, Previous is in horizontal field manager. So I need 2.PNG scrollable.
Here is code to draw and setting layout for 2.PNG image and its draw class drawimage.java
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class drawimage extends VerticalFieldManager
{
private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;
private Bitmap _currentPicture;
private int fixedHeight;
/**
* Constructor.
* @param text - the text to be displayed on the button
* @param style - combination of field style bits to specify display
attributes
*/
drawimage(String text, long style)
{
super(style);
_font = getFont();
_label = text;
_labelHeight = _font.getHeight();
_labelWidth = _font.getAdvance(_label);
_currentPicture = Bitmap.getBitmapResource(text);
this.fixedHeight = 436;
}
/**
* @return The text on the button
*/
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#getPreferredHeight()
*/
public int getPreferredHeight()
{
return fixedHeight;
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#getPreferredWidth()
*/
public int getPreferredWidth()
{
return _labelWidth + 8;
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#layout(int, int)
*/
/* protected void layout(int width, int height)
{
setExtent(360,436);
}*/
protected void sublayout(int width, int height)
{
super.sublayout(width, fixedHeight);
setExtent(width, fixedHeight);
//setExtent(width, 436);
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#paint(Graphics)
*/
protected void paint(Graphics graphics)
{
// Draw the background picture
graphics.drawBitmap(0,0,getWidth(),436, _currentPicture, 0, 0);
}
}
Here i have not given class file reference for Next & Previous field manager. They are add in Horizontal filed manager hfm with height 70. So it has no problem but I have maintian scrolling with vertical feild manager mainMgr.
Please help me.
Thanks in Advanced.
Vimal