Trying to reduce the height of a DateField
from default 53 to 32, but to no avail. The height stays the same with the result that the text appears cut out towards the bottom of the background which is smaller in height (32).
I tried 2 ways:
DateField dtf = new DateField(label, defaultDateTime, DateField.DATE_TIME | DrawStyle.LEFT | DrawStyle.TOP | Field.FOCUSABLE | Field.READONLY )
{
protected void layout(int width, int height)
{
Bitmap bmp = UIElements.GetBitmap(UIElements.IMG_DROPDOWN_BG, true);
width = bmp.getWidth();
height = bmp.getHeight();
super.setExtent(width, height);
super.layout(width, height);
}
};
2nd method (based on a Stack Overflow post):
public class MyDateManager extends VerticalFieldManager {
protected DateField dateField_ = null;
public MyDateManager(String label, long defaultDateTime) {
super(Manager.FIELD_HCENTER | Manager.FIELD_VCENTER);
dateField_ = new DateField(label, defaultDateTime, DateField.DATE_TIME |
Field.FIELD_HCENTER | DrawStyle.HCENTER | Field.FOCUSABLE | Field.READONLY);
this.add(dateField_);
}
protected void sublayout(int width, int height) {
Bitmap bmp = UIElements.GetBitmap(UIElements.IMG_DROPDOWN_BG, false);
width = bmp.getWidth();
height = bmp.getHeight();
layoutChild(dateField_, width, height);
dateField_.setBackground(BackgroundFactory.createBitmapBackground(bmp, 0, 0, Background.REPEAT_NONE));
int h = dateField_.getHeight();
setExtent(width, height);
}
}
Please suggest.
Thanks
Second method is a horrible approach (messing with VerticalFieldManager's height will get you a lot of problems).
Try the first method again, but this time call super.layout
first:
DateField dtf = new DateField(label, defaultDateTime, DateField.DATE_TIME | DrawStyle.LEFT | DrawStyle.TOP | Field.FOCUSABLE | Field.READONLY )
{
protected void layout(int width, int height) {
super.layout(width, height);
Bitmap bmp = UIElements.GetBitmap(UIElements.IMG_DROPDOWN_BG, true);
width = bmp.getWidth();
height = bmp.getHeight();
super.setExtent(width, height);
}
};
Notice that using this approach you might also get glitches, as you are blindly overriding a method without considering the rest of the class. To do this safely you would need to have access to the parent class source, and you don't.
I'd suggest to extend HorizontalFieldManager
(override sublayout
) to have a fixed height (Never VFM because the scrolling goes in the same direction you are trying to make fixed). Then place inside a regular date field that uses all the available height (pass the flag Field.USE_ALL_HEIGHT
in the constructor).