图像消失了对焦后 [英] Image gone After Focusing

查看:235
本文介绍了图像消失了对焦后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href=\"http://desmond.imageshack.us/Himg20/scaled.php?server=20&filename=beforedocus.png&res=landing\"相对=nofollow>这是前焦点状态。它做工精细。

<一个href=\"http://desmond.imageshack.us/Himg594/scaled.php?server=594&filename=focusing.png&res=landing\"相对=nofollow>这是聚焦状态。它做工精细。

<一个href=\"http://desmond.imageshack.us/Himg833/scaled.php?server=833&filename=afterfocus.png&res=landing\"相对=nofollow>这是后焦点状态。它发生的问题,其中的图像了。

它工作正常的右上方,但左上角的图像有问题。

下面是我的自定义 VerticalFieldManager

公共类Custom_TopField扩展Horizo​​ntalFieldManager工具
    FieldChangeListener {私人位图BG = Bitmap.getBitma $ P $的PSource(header_bar.png);
私人位图下载= Bitmap.getBitma $ P $的PSource(btn_download.png);
私人位图downloadactive =位图
        .getBitma $ P $的PSource(btn_download_active.png);
私人位图刷新= Bitmap.getBitma $ P $的PSource(icon_refresh.png);
私人位图refreshactive =位图
        .getBitma $ P $的PSource(icon_refresh_active.png);
私人位图背= Bitmap.getBitma $ P $的PSource(btn_back.png);
私人位图backctive = Bitmap.getBitma $ P $的PSource(btn_back_active.png);
私人位图新闻= Bitmap.getBitma $ P $的PSource(icon_news.png);
私人位图newsactive =位图
        .getBitma $ P $的PSource(icon_news_active.png);私人Custom_ButtonField downloadbtn,refreshbtn,backbtn,newsbtn;
私人Custom_LabelField称号;Custom_TopField(最终MainScreen mainscreen){
    背景背景= BackgroundFactory.createBitmapBackground(BG);
    的setBackground(背景);
    标题=新Custom_LabelField(东方日报,DrawStyle.ELLIPSIS
            | LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER
            | Field.FOCUSABLE,Color.WHITE){
        保护布尔navigationClick(INT的地位,诠释时间){
            。Main.getUiApplication()pushScreen(新Main_AllLatestNews());
            。Main.getUiApplication()popScreen(mainscreen);
            返回true;
        }
    };
    title.setFont(Font.getDefault()获得(Font.BOLD,33));
    添加标题);    downloadbtn =新Custom_ButtonField(下载,downloadactive,
            downloadactive);
    downloadbtn.setChangeListener(本);
    加(downloadbtn);    refreshbtn =新Custom_ButtonField(刷新,refreshactive,
            refreshactive);
    refreshbtn.setChangeListener(本);
    加(refreshbtn);    backbtn =新Custom_ButtonField(背部,backctive,backctive);
    backbtn.setChangeListener(本);
    加(backbtn);    / * newsbtn =新Custom_ButtonField(新闻,newsactive,newsactive);
    newsbtn.setChangeListener(本);
    加(newsbtn); * /
}保护无效sublayout(INT宽度,高度INT){
    场场= getfield命令(0);
    layoutChild(场,120,Font.getDefault()的getHeight());
    setPositionChild(场,(GET preferredWidth() - title.getWidth())/ 2,
            15);    字段= getfield命令(1);
    layoutChild(场,download.getWidth(),download.getHeight());
    setPositionChild(场,拿到preferredWidth()
             - (download.getWidth()+ 10),
            GET preferredHeight() - (download.getHeight()+ 5));    字段= getfield命令(2);
    layoutChild(场,refresh.getWidth(),refresh.getHeight());
    setPositionChild(场,
            获得preferredWidth() - (refresh.getWidth()+ 10)
            GET preferredHeight() - (refresh.getHeight()+ 5));    字段= getfield命令(3);
    layoutChild(场,back.getWidth(),back.getHeight());
    setPositionChild(场,10,5);    / *字段= getfield命令(4);
    layoutChild(场,news.getWidth(),news.getHeight());
    setPositionChild(场,10,5); * /    宽度= Math.min(宽度,获得preferredWidth());
    身高= Math.min(高度,获得preferredHeight());
    setExtent(宽度,高度);
}公众诠释的get preferredHeight(){
    返回70;
}公众诠释的get preferredWidth(){
    返回Display.getWidth();
}公共无效漆(图形图像){
    INT rectHeight = GET preferredHeight();
    INT rectWidth = GET preferredWidth();    graphics.drawRect(0,0,rectWidth,rectHeight);
    super.paint(图形);
}公共无效fieldChanged(场场,诠释上下文){
    如果(场== downloadbtn){    }否则如果(场== refreshbtn){    }否则如果(场== backbtn){    }否则如果(场== newsbtn){    }
}
}

下面是自定义按钮字段

 公共类Custom_ButtonField扩展ButtonField字段{
位图mNormal;
位图mFocused;
位图mActive;INT mWidth;
INT mHeight;私人INT颜色= -1;
字符串文本;公共Custom_ButtonField(位图正常,位图集中,位图有效){
    超(CONSUME_CLICK | Field.FOCUSABLE);
    mNormal =正常;
    mFocused =集中;
    mActive =有效;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0,0,0,0);
    setPadding(0,0,0,0);
    setBorder(BorderFactory.createSimpleBorder(新XYEdges(0,0,0,0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(新XYEdges(0,0,0,0)));
}公共Custom_ButtonField(字符串文本,位图正常,位图集中,
        位图活跃,诠释颜色){
    超(CONSUME_CLICK | Field.FOCUSABLE);
    this.color =颜色;
    mNormal =正常;
    mFocused =集中;
    mActive =有效;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0,0,0,0);
    setPadding(0,0,0,0);
    setBorder(BorderFactory.createSimpleBorder(新XYEdges(0,0,0,0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(新XYEdges(0,0,0,0)));
    this.text =文本;
}保护无效的onfocus(INT方向){
    super.onFocus(方向);
}保护无效onUnfocus(){
    super.onUnfocus();
}保护无效漆(图形图像){
    位图位图= NULL;
    开关(getVisu​​alState()){
    案例VISUAL_STATE_NORMAL:
        位= mNormal;
        打破;
    案例VISUAL_STATE_FOCUS:
        位= mFocused;
        打破;
    案例VISUAL_STATE_ACTIVE:
        位= mActive;
        打破;
    默认:
        位= mNormal;
    }
    graphics.drawBitmap(0,0,bitmap.getWidth(),bitmap.getHeight(),
            位图,0,0);
    graphics.setFont(Font.getDefault()获得(Font.BOLD,25));
    graphics.setColor(颜色);
    graphics.drawText(文字,(mNormal.getWidth() - Font.getDefault()
            .getAdvance(文本))/ 2,((mNormal.getHeight() - 字体
            .getDefault()。的getHeight())/ 2)+ 10,DrawStyle.HCENTER
            | DrawStyle.VCENTER);
}公众诠释的get preferredWidth(){
    返回mWidth;
}公众诠释的get preferredHeight(){
    返回mHeight;
}保护无效布局(INT宽度,高度INT){
    setExtent(mWidth,mHeight);
}
}


解决方案

这是第二个问题就这样我见过过去几周

背景

要了解该解决方案,首先应该了解黑莓的基本UI类。

首先,我们必须字段。 A 字段的基类是正常的UI的组件的的。如果你自己从头编写UI组件,,然后你会继承字段

公共类进myWidget扩展字段{

不过,如果已经有一个黑莓手机的类,它需要几乎什么,你只需要改变它的行为一点,那么你会继承别的东西。例如:

公共类MyButtonWidget扩展ButtonField字段{

同样的模式存在的的 管理​​。如果你是从头开始编写一个管理​​ ,然后延长管理​​

公共类MyManager扩展管理器{

其中涉及这样

据黑莓文档


  

实现自己的布局管理器


  
  

如果你有特殊需要,你
  可以实现自己的经理。扩展管理器类,
  实施sublayout,获得preferredWidth,并获得preferredHeight。对于
  效率,可以选择覆盖subpaint。


但是,如果现有的管理器子类已经做你最需要什么,你只是想自定义它,那么你可能会考虑延长该子类:

公共类MyHorizo​​ntalManager扩展Horizo​​ntalFieldManager {

在你的情况,你的 Custom_TopField 正在做的所有作为一个完全自定义的管理​​要求的工作(见上突出引自的javadoc)。那么,有什么理由让你不是真正的延长 Horizo​​ntalFieldManager 。 A Horizo​​ntalFieldManager 用于当你只是想添加()您的领域,并让他们都奠定了水平。但是,你这样做明确在你的 sublayout() code。事实证明,它看起来像你的逻辑与基类的竞争。

解决方案

所以,你应该做的,是有你的类只是延长管理​​

公共类Custom_TopField扩展管理器实现FieldChangeListener {

如果你这样做,你将需要调用不同的超级构造函数。像这样的东西(你可能想挑选不同式样的常量根据您的需要):

Custom_TopField(最终MainScreen mainscreen){
   超(Manager.USE_ALL_WIDTH | Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL);

另一个方法是根本就没有实施 sublayout(),延长 Horizo​​ntalFieldManager 像你原来有,然后控制布局与孩子的字段'利润 风格标志。但是,因为我在上面只需要更换2号线code都给解决方案,这可能是最简单的了你这一次。

其他问题(S)

我也注意到在code和截图,该下载按钮不会显示出来。我不知道你所有的PNG图像的具体规模,但如果刷新和下载图像的大小相同,则当前的逻辑,我只是​​摆出刷新按钮,在右侧的下载按钮。因此,下载按钮被隐藏。这可能不是你想要的?

This is before focus state. It work fine.

This is on focusing state. It work fine.

This is after focus state. It occurred problem where the image gone.

It works fine for the top right but top left image got problem.

Here is my custom VerticalFieldManager:

public class Custom_TopField extends HorizontalFieldManager implements
    FieldChangeListener {

private Bitmap bg = Bitmap.getBitmapResource("header_bar.png");
private Bitmap download = Bitmap.getBitmapResource("btn_download.png");
private Bitmap downloadactive = Bitmap
        .getBitmapResource("btn_download_active.png");
private Bitmap refresh = Bitmap.getBitmapResource("icon_refresh.png");
private Bitmap refreshactive = Bitmap
        .getBitmapResource("icon_refresh_active.png");
private Bitmap back = Bitmap.getBitmapResource("btn_back.png");
private Bitmap backctive = Bitmap.getBitmapResource("btn_back_active.png");
private Bitmap news = Bitmap.getBitmapResource("icon_news.png");
private Bitmap newsactive = Bitmap
        .getBitmapResource("icon_news_active.png");

private Custom_ButtonField downloadbtn, refreshbtn, backbtn, newsbtn;
private Custom_LabelField title;

Custom_TopField(final MainScreen mainscreen) {
    Background background = BackgroundFactory.createBitmapBackground(bg);
    setBackground(background);
    title = new Custom_LabelField("东方日报", DrawStyle.ELLIPSIS
            | LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER
            | Field.FOCUSABLE, Color.WHITE) {
        protected boolean navigationClick(int status, int time) {
            Main.getUiApplication().pushScreen(new Main_AllLatestNews());
            Main.getUiApplication().popScreen(mainscreen);
            return true;
        }
    };
    title.setFont(Font.getDefault().derive(Font.BOLD, 33));
    add(title);

    downloadbtn = new Custom_ButtonField(download, downloadactive,
            downloadactive);
    downloadbtn.setChangeListener(this);
    add(downloadbtn);

    refreshbtn = new Custom_ButtonField(refresh, refreshactive,
            refreshactive);
    refreshbtn.setChangeListener(this);
    add(refreshbtn);

    backbtn = new Custom_ButtonField(back, backctive, backctive);
    backbtn.setChangeListener(this);
    add(backbtn);

    /*newsbtn = new Custom_ButtonField(news, newsactive, newsactive);
    newsbtn.setChangeListener(this);
    add(newsbtn);*/
}

protected void sublayout(int width, int height) {
    Field field = getField(0);
    layoutChild(field, 120, Font.getDefault().getHeight());
    setPositionChild(field, (getPreferredWidth() - title.getWidth()) / 2,
            15);

    field = getField(1);
    layoutChild(field, download.getWidth(), download.getHeight());
    setPositionChild(field, getPreferredWidth()
            - (download.getWidth() + 10),
            getPreferredHeight() - (download.getHeight() + 5));

    field = getField(2);
    layoutChild(field, refresh.getWidth(), refresh.getHeight());
    setPositionChild(field,
            getPreferredWidth() - (refresh.getWidth() + 10),
            getPreferredHeight() - (refresh.getHeight() + 5));

    field = getField(3);
    layoutChild(field, back.getWidth(), back.getHeight());
    setPositionChild(field, 10, 5);

    /*field = getField(4);
    layoutChild(field, news.getWidth(), news.getHeight());
    setPositionChild(field, 10, 5);*/

    width = Math.min(width, getPreferredWidth());
    height = Math.min(height, getPreferredHeight());
    setExtent(width, height);
}

public int getPreferredHeight() {
    return 70;
}

public int getPreferredWidth() {
    return Display.getWidth();
}

public void paint(Graphics graphics) {
    int rectHeight = getPreferredHeight();
    int rectWidth = getPreferredWidth();

    graphics.drawRect(0, 0, rectWidth, rectHeight);
    super.paint(graphics);
}

public void fieldChanged(Field field, int context) {
    if (field == downloadbtn) {

    } else if (field == refreshbtn) {

    } else if (field == backbtn) {

    } else if (field == newsbtn) {

    }
}
}

Here is custom button field

public class Custom_ButtonField extends ButtonField {
Bitmap mNormal;
Bitmap mFocused;
Bitmap mActive;

int mWidth;
int mHeight;

private int color = -1;
String text;

public Custom_ButtonField(Bitmap normal, Bitmap focused, Bitmap active) {
    super(CONSUME_CLICK | Field.FOCUSABLE);
    mNormal = normal;
    mFocused = focused;
    mActive = active;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0, 0, 0, 0);
    setPadding(0, 0, 0, 0);
    setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
}

public Custom_ButtonField(String text, Bitmap normal, Bitmap focused,
        Bitmap active, int color) {
    super(CONSUME_CLICK | Field.FOCUSABLE);
    this.color = color;
    mNormal = normal;
    mFocused = focused;
    mActive = active;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0, 0, 0, 0);
    setPadding(0, 0, 0, 0);
    setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    this.text = text;
}

protected void onFocus(int direction) {
    super.onFocus(direction);
}

protected void onUnfocus() {
    super.onUnfocus();
}

protected void paint(Graphics graphics) {
    Bitmap bitmap = null;
    switch (getVisualState()) {
    case VISUAL_STATE_NORMAL:
        bitmap = mNormal;
        break;
    case VISUAL_STATE_FOCUS:
        bitmap = mFocused;
        break;
    case VISUAL_STATE_ACTIVE:
        bitmap = mActive;
        break;
    default:
        bitmap = mNormal;
    }
    graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
            bitmap, 0, 0);
    graphics.setFont(Font.getDefault().derive(Font.BOLD, 25));
    graphics.setColor(color);
    graphics.drawText(text, (mNormal.getWidth() - Font.getDefault()
            .getAdvance(text)) / 2, ((mNormal.getHeight() - Font
            .getDefault().getHeight()) / 2) + 10, DrawStyle.HCENTER
            | DrawStyle.VCENTER);
}

public int getPreferredWidth() {
    return mWidth;
}

public int getPreferredHeight() {
    return mHeight;
}

protected void layout(int width, int height) {
    setExtent(mWidth, mHeight);
}
}

解决方案

This is the second problem just like this I've seen in the last couple weeks.

Background

To understand the solution, first you should understand the basic UI classes in BlackBerry.

First, we have the Field class. A Field is the base class of the normal UI components. If you write a UI component yourself, from scratch, then you would subclass Field:

public class MyWidget extends Field {

However, if there already exists a BlackBerry class that does almost what you need, and you just need to change its behaviour a bit, then you would subclass something else. For example:

public class MyButtonWidget extends ButtonField {

The same pattern exists for the Manager class. If you are writing a Manager from scratch, then extend Manager:

public class MyManager extends Manager {

which involves doing this, according to the BlackBerry docs:

Implementing your own layout manager

If you have particular needs, you can implement your own manager. Extend the Manager class, and implement sublayout, getPreferredWidth, and getPreferredHeight. For efficiency, you may optionally override subpaint.

However, if an existing Manager subclass already does most of what you need, and you just want to customize it, then you might consider extending that subclass:

public class MyHorizontalManager extends HorizontalFieldManager {

In your case, your Custom_TopField is doing all of the required work for a fully custom Manager (see the highlighted quote above from the javadocs). So, there's not really any reason for you to extend HorizontalFieldManager. A HorizontalFieldManager is used when you just want to add() your fields, and have them all laid out horizontally. But, you do that explicitly in your sublayout() code. As it turns out, it looks like your logic is competing with the base class.

Solution

So, what you should do, is have your class just extend Manager:

public class Custom_TopField extends Manager implements FieldChangeListener {

If you do that, you will need to call a different super constructor. Something like this (you might want to pick different style constants depending on your needs):

Custom_TopField(final MainScreen mainscreen) {
   super(Manager.USE_ALL_WIDTH | Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL);

Another alternative would be to simply not implement sublayout(), extend HorizontalFieldManager like you originally had, and then control layout with the child fields' margins and long style flags. But, since the solution I gave above requires only changing 2 lines of code, that's probably the easiest for you this time.

Other Problem(s)

I also noticed in your code, and screenshots, that the Download button doesn't show up. I don't know the exact size of all your png images, but if the refresh and download images are the same size, then your current logic is just laying out the refresh button right over the download button. So, the download button is hidden. That's probably not what you want?

这篇关于图像消失了对焦后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆