ОБНОВЛЕНИЕ - пользовательская полоса прокрутки
пользовательская полоса прокрутки http://img146.imageshack.us/img146/7775/scroll.png
VerticalFieldManager с пользовательским ограничением размера и прокруткой:
class SizedVFM extends VerticalFieldManager {
int mWidth;
int mHeight;
public SizedVFM(int width, int height) {
super(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
mWidth = width;
mHeight = height;
}
public int getPreferredHeight() {
return mHeight;
}
public int getPreferredWidth() {
return mWidth;
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(maxWidth, maxHeight);
setExtent(getPreferredWidth(), getPreferredHeight());
}
protected void paint(Graphics graphics) {
super.paint(graphics);
if (getVisibleHeight() < getVirtualHeight()) {
int y1 = 0, y2 = 0, x1 = 0, x2 = 0;
int scrollOff = getVerticalScroll();
if (scrollOff > 0) {
y1 = scrollOff + 12;
y2 = scrollOff + 2;
x1 = getVisibleWidth() - 20;
x2 = getVisibleWidth() - 2;
graphics.setColor(Color.DARKRED);
int[] xPts = new int[] { x1, x2, x1 + 9 };
int[] yPts = new int[] { y1, y1, y2 };
graphics.drawFilledPath(xPts, yPts, null, null);
}
if (scrollOff < (getVirtualHeight() - getVisibleHeight())) {
y1 = scrollOff + getVisibleHeight() - 12;
y2 = scrollOff + getVisibleHeight() - 2;
x1 = getVisibleWidth() - 20;
x2 = getVisibleWidth() - 2;
graphics.setColor(Color.DARKRED);
int[] xPts = new int[] { x1, x2, x1 + 9 };
int[] yPts = new int[] { y1, y1, y2 };
graphics.drawFilledPath(xPts, yPts, null, null);
}
}
}
}
Поля для рисования и текста:
class HeaderPainting extends SizedVFM {
BitmapField mBitmapField;
public HeaderPainting(Bitmap bitmap, int width, int height) {
super(width, height);
add(mBitmapField = new BitmapField(bitmap, FOCUSABLE));
}
}
class FooterText extends SizedVFM {
ExRichTextField mTextField;
public FooterText(String text, int width, int height) {
super(width, height);
int bgColor = Color.SANDYBROWN;
int textColor = Color.DARKRED;
add(mTextField = new ExRichTextField(text, bgColor, textColor));
}
class ExRichTextField extends RichTextField {
int mTextColor;
int mBgColor;
public ExRichTextField(String text, int bgColor, int textColor) {
super(text);
mTextColor = textColor;
mBgColor = bgColor;
}
protected void paint(Graphics graphics) {
graphics.clear();
graphics.setColor(mBgColor);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.setColor(mTextColor);
super.paint(graphics);
}
}
}
Пример использования:
class Scr extends MainScreen {
HeaderPainting mBitmapField;
FooterText mTextField;
public Scr() {
int width = Display.getWidth();
int height = Display.getHeight() / 2;
Bitmap bitmap = customPaint(width, height);
String text = "Lorem ipsum dolor sit amet, consectetuer "
+ "adipiscing elit, sed diam nonummy nibh euismod "
+ "tincidunt ut laoreet dolore magna aliquam erat "
+ "volutpat. Ut wisi enim ad minim veniam, quis "
+ "nostrud exerci tation ullamcorper suscipit "
+ "lobortis nisl ut aliquip ex ea commodo consequat. "
+ "Duis autem vel eum iriure dolor in hendrerit in "
+ "vulputate velit esse molestie consequat, vel "
+ "illum dolore eu feugiat nulla facilisis at vero "
+ "eros et accumsan et iusto odio dignissim qui "
+ "blandit praesent luptatum zzril delenit augue "
+ "duis dolore te feugait nulla facilisi.";
add(mBitmapField = new HeaderPainting(bitmap, width, height));
add(mTextField = new FooterText(text, width, height));
}
protected Bitmap customPaint(int width, int height) {
Bitmap bmp = new Bitmap(width, height);
Graphics graphics = new Graphics(bmp);
graphics.setColor(Color.BLUE);
graphics.fillRect(10, 10, width - 20, height - 20);
graphics.setColor(Color.RED);
graphics.fillRect(10, 10, 50, height - 20);
return bmp;
}
}
Если вам не нравится фокусировка внутри RichTextField, см.
Blackberry Java: TextField без каретки?