0
我在MainScreen的setStatus方法中添加了按鈕。現在整個HFM都是可點擊的我不知道爲什麼?請指導。下面的代碼:
爲什麼整個HorizontalFieldManager可點擊?
setStatus(setFooter());
...
public Field setFooter() {
HorizontalFieldManager hfm1 = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);
Bitmap bm;
bm = Bitmap.getBitmapResource("statusImage.PNG");
Background bg = BackgroundFactory.createBitmapBackground(bm, Background.POSITION_X_LEFT, Background.POSITION_Y_BOTTOM, Background.REPEAT_SCALE_TO_FIT);
hfm1.setBackground(bg);
hfm1.add(new DummyField(bm.getHeight()));
hfm1.add(backButton);
hfm1.add(nextButton);
return hfm1;
}
空場:
class DummyField extends Field {
private int logoHeight;
public DummyField(int height) {
logoHeight = height;
}
protected void layout(int width, int height) {
setExtent(1, logoHeight);
}
protected void paint(Graphics graphics) {
}
}
我也重寫這些方法(lionscribe implementation),以避免HFM被點擊,但它不工作:
protected boolean touchEvent(TouchEvent message)
{
int event = message.getEvent();
if (event == TouchEvent.CLICK || event == TouchEvent.UNCLICK)
{
// Ignore clcik events that happen outside any fields
if (getFieldAtLocation(message.getX(1), message.getY(1)) == -1)
return true; // kill the event
}
return super.touchEvent(message);
}
// The regular getFieldAtLocation returns wrong values in open spaces in complex managers, so we override it
public int getFieldAtLocation(int x, int y)
{
XYRect rect = new XYRect();
int index = getFieldCount() -1;
while (index >= 0)
{
getField(index).getExtent(rect);
if (rect.contains(x, y))
break;
--index;
}
return index;
}