I'm afraid it has nothing to do with hierarchy. Notice that the center 
absolute is not the parent of that container, because it is replaced here:

f.replace(loading, l, null);

I have elaborated the code a bit more to see if it can clarify something. I 
have resized the same image, so now we have 3 of them:

- 1536x4272
- 1536x3272
- 768x2136

I also have removed the center absolute and the scrollable container, so we 
can reduce possibilities.

If you build and run on device, only the first one is problematic and the 
rest are fine. I'm not sure it is an edge case and what is bugging me is 
why only that size fails, and why it shows fine on simulator and not on 
devices... Anyway, here is the code:

public class Prueba {   
    private Form current;
    final static String[] resolutions = new String[]{"1536x4272.png", 
"1536x3272.png", "768x2136.png"};   
    
    public void init(Object context) {
        Toolbar.setGlobalToolbar(true);
    }
    
    public void start() {
        if(current != null){
            current.show();
            return;
        }
        
        Form f1 = new Form(new FlowLayout(Component.CENTER));
        
f1.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,
 
false, 300));
        Command back = new Command("Back") {
            @Override
            public void actionPerformed(ActionEvent evt) {
                f1.showBack();
            }            
        };        
        Button b1 = new Button ("Image " + resolutions[0]);        
        Button b2 = new Button ("Image " + resolutions[1]);
        Button b3 = new Button ("Image " + resolutions[2]);
        Container c1 = new Container(new FlowLayout());
        c1.add(b1).add(b2).add(b3);
        int[] selected = new int[1];
        String[] downloadLink = new String[1];        
        b1.addActionListener((evt) -> {
            selected[0] = 0;
            downloadLink[0] = 
"https://dl.dropboxusercontent.com/u/47281022/IMGP0_"; + resolutions[0];     
       
            showImage(back, selected, downloadLink);       
        });
        b2.addActionListener((evt) -> {
            selected[0] = 1;            
            downloadLink[0] = 
"https://dl.dropboxusercontent.com/u/47281022/IMGP0_"; + resolutions[1];     
                       
            showImage(back, selected, downloadLink);                   
        });
        b3.addActionListener((evt) -> {
            selected[0] = 2;
            downloadLink[0] = 
"https://dl.dropboxusercontent.com/u/47281022/IMGP0_"; + resolutions[2];  
            showImage(back, selected, downloadLink);                   
        });
        f1.add(c1);
        f1.show();
    }
    private void showImage(Command back, int[] selected, String[] 
downloadLink) {
        Form f2 = new Form(new BoxLayout(BoxLayout.Y_AXIS));  
        
f2.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,
 
false, 300));                        
        f2.setBackCommand(back);
        f2.getToolbar().addCommandToLeftBar(back);   
        f2.show();                        
        String path = FileSystemStorage.getInstance().getAppHomePath() + 
"IMGP0_";        
        if (FileSystemStorage.getInstance().exists(path + 
resolutions[selected[0]])) {
            try {
                EncodedImage img = 
EncodedImage.create(FileSystemStorage.getInstance().openInputStream(path + 
resolutions[selected[0]]));
                int imgHeightDevice = 
(Display.getInstance().getDisplayWidth() * img.getHeight()) / 
img.getWidth();                        
                Label l = new Label() {
                    @Override
                    protected Dimension calcPreferredSize() {
                        return new 
Dimension(Display.getInstance().getDisplayWidth(), imgHeightDevice);
                    }                            
                };                        
                
l.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
                l.getAllStyles().setBgImage(img);                       
                f2.add(l);    
                f2.repaint();
            } catch (IOException io) {                
            }
        } else {
            Util.downloadImageToFileSystem(downloadLink[0], 
                path + resolutions[selected[0]], 
                new CallbackAdapter(){
                    @Override
                    public void onSucess(Object value) {
                        Image img = (Image) value;
                        int imgHeightDevice = 
(Display.getInstance().getDisplayWidth() * img.getHeight()) / 
img.getWidth();                        
                        Label l = new Label() {
                            @Override
                            protected Dimension calcPreferredSize() {
                                return new 
Dimension(Display.getInstance().getDisplayWidth(), imgHeightDevice);
                            }                            
                        };                        
                        
l.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
                        l.getAllStyles().setBgImage(img);                   
    
                        f2.add(l);
                        f2.repaint();
                    }
                });
        }
        
    }
    public void stop() {
        current = Display.getInstance().getCurrent();
    }    
    public void destroy() {
    }
}


-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/47e3d155-759f-42d3-94b8-d4931c22fbbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to