我有一个应用程序,它显示一个带有应用程序横幅和标题+图像+详细信息(RichTextField)的新闻屏幕以及屏幕底部的广告横幅,所以一旦我向下滚动阅读详细信息,我就无法回到顶部..正如您在这些图片中看到的那样,它停在屏幕中间..我不知道为什么..当您在触摸屏设备上使用触摸时,它可以完美运行
这是我的屏幕代码...请帮助
public class DetailsScreen_en extends MainScreen {
AppManager appManager;
private Detailsbean_en bean;
private AppManager manager;
private BitmapField bitmapField;
private LabelField titleField;
private LabelField dateField;
private RichTextField articleField;
private Bitmap bitmap;
private BitmapField bar;
private HorizontalFieldManager hfm;
Adsbean[] adsBean;
BitmapField ad;
VerticalFieldManager otherStuff;
VerticalFieldManager vvv;
Timer time;
TimerTask task;
private HorizontalFieldManager admanager;
private int adCounter = 0;
private boolean status;
private int tour;
public DetailsScreen_en(boolean status, int tour) {
appManager = AppManager.getInstance();
adsBean = appManager.getAdsBean();
Locale.setDefault(Locale.get(Locale.LOCALE_en));
// ScreenOne.showLoadingScreen();
this.status = status;
this.tour = tour;
XYEdges padding = new XYEdges(10, 10, 10, 10);
HTMLParser parser = new HTMLParser();
vvv = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL
| Field.FOCUSABLE) {
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, Display.getHeight() - ad.getHeight());
}
};
hfm = new HorizontalFieldManager();
bar = new BitmapField(DesignSizes.FanClubBar(), Field.FIELD_HCENTER
| Field.NON_FOCUSABLE | Field.READONLY);
hfm.add(bar);
vvv.add(hfm);
hfm = new HorizontalFieldManager();
manager = AppManager.getInstance();
bean = manager.getBean_en();
// System.out.println("DATE: "+ bean.getNewsDate() );
// another try ...
Date _date;
Calendar _cal = Calendar.getInstance();
_cal.set(Calendar.YEAR,
Integer.parseInt(bean.getNewsDate().substring(0, 4)));
_cal.set(Calendar.MONTH,
Integer.parseInt(bean.getNewsDate().substring(5, 7)) - 1);
_cal.set(Calendar.DAY_OF_MONTH,
Integer.parseInt(bean.getNewsDate().substring(8, 10)));
_date = _cal.getTime();
DateFormat dff = new SimpleDateFormat("dd MMMM yyyy");
String datedatedate = dff.formatLocal(_date.getTime());
dateField = new LabelField(datedatedate);
dateField.setPadding(padding);
titleField = new LabelField(bean.getNewsTitle(), Field.FIELD_LEFT) {
protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
graphics.setColor(Color.ORANGE);
super.paint(graphics);
}
};
titleField.setPadding(padding);
Font font = Font.getDefault().derive(Font.BOLD, 9, Ui.UNITS_pt);
titleField.setFont(font);
bitmapField = new BitmapField(DesignSizes.newsIsLoading(),
Field.FIELD_HCENTER);
bitmapField.setPadding(padding);
setBitmap(bean.getImgUrl());
articleField = new RichTextField(parser.clean(bean.getNewsArticle()),
RichTextField.USE_TEXT_WIDTH | RichTextField.TEXT_ALIGN_LEFT
| RichTextField.READONLY);
// bitmap field for the add bitmap
ad = new BitmapField(DesignSizes.adBanner(), Field.FIELD_TRAILING
| Field.FIELD_HCENTER);
// horizontal field manager to set the bitmapfield away from the
// scrollable screen .. as its required to be only
// on the bottom of the screen !
admanager = new HorizontalFieldManager(
VerticalFieldManager.NO_VERTICAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLLBAR
| Field.FIELD_HALIGN_MASK);
// the other stuff title bar + action bar + itemRow + button more
otherStuff = new VerticalFieldManager(
VerticalFieldManager.VERTICAL_SCROLL) {
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, Display.getHeight() - ad.getHeight());
}
};
admanager.add(ad);
// font for the article
Font artFont = Font.getDefault().derive(Font.PLAIN, 6, Ui.UNITS_pt);
articleField.setPadding(padding);
articleField.setFont(artFont);
vvv.add(dateField);
vvv.add(titleField);
vvv.add(bitmapField);
vvv.add(articleField);
add(vvv);
add(admanager);
switch (Display.getWidth()) {
case 320:
getAd(adsBean[adCounter].getBlackberry320());
break;
case 360:
getAd(adsBean[adCounter].getBlackberry360());
break;
case 480:
getAd(adsBean[adCounter].getBlackberry480());
break;
case 640:
getAd(adsBean[adCounter].getBlackberry640());
break;
}
}
private void setBitmap(final String url) {
// TODO Auto-generated method stub\\
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
// TODO Auto-generated method stub
final DownLoadImage dope = new DownLoadImage(url);
bitmap = dope.getImage();
Bitmap resized_bitmap = bitmap;
Bitmap tempbitmap = new Bitmap(Display.getWidth() - 20,
(int) ((Display.getWidth() - 20) * 0.458));
tempbitmap.createAlpha(Bitmap.TRUE_WHITE);
resized_bitmap.scaleInto(tempbitmap, Bitmap.FILTER_LANCZOS);
bitmap = tempbitmap;
bitmapField.setBitmap(bitmap);
}
});
}
protected boolean keyDown(int keycode, int time) {
int key = Keypad.key(keycode);
if (key == Characters.ESCAPE) {
try{
this.time.cancel();
}catch(Exception e){
}
UiApplication.getUiApplication().pushScreen(
new NewsScreen_en(status, tour));
return true;
}
return super.keyDown(keycode, time);
}
// =============================================================================================
// for getting the ads ...
// =============================================================================================
private void loadAD(int timer) {
System.out.println("Timer start! ");
time = new Timer();
task = new TimerTask() {
public void run() {
time.cancel();
switch (Display.getWidth()) {
case 320:
getAd(adsBean[adCounter].getBlackberry320());
break;
case 360:
getAd(adsBean[adCounter].getBlackberry360());
break;
case 480:
getAd(adsBean[adCounter].getBlackberry480());
break;
case 640:
getAd(adsBean[adCounter].getBlackberry640());
break;
}
System.out.println("tik tik tik");
}
};
time.schedule(task, timer * 1000);
}
private void getAd(final String url) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
// TODO Auto-generated method stub
final DownLoadImage dope = new DownLoadImage(url);
Bitmap bitmap = dope.getImage();
ad.setBitmap(bitmap);
}
});
//for saving more memo
switch(Integer.parseInt(adsBean[adCounter].getAdDuration())){
case 0:
//
break;
default:
System.out.println("loading ad! ");
adCounter++ ;
if(adCounter == adsBean.length || adCounter > adsBean.length){
adCounter = 0;
}
loadAD(Integer.parseInt(adsBean[adCounter].getAdDuration()));
break;
}
}
}