我有一个应用程序,它显示一个带有应用横幅和标题+图像+详细信息(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;
}
}
}
答案 0 :(得分:1)
要使屏幕可滚动,请为其添加可聚焦元素。如果屏幕或其区域没有可聚焦元素,则滚动此屏幕/区域时会遇到问题。
作为选项,在每个不可聚焦的字段后添加空的和可聚焦的分隔符字段。它不会影响应用程序的外观,但会有助于滚动。