0

我在网格中有一个图像,当 PartView 调整大小时它会缩放。如果 BarsView 开始时的高度小于 64 高(画布的大小),则图像的底部部分会在初始大小以下被截断。如果它开始时大于调整后的大小,则 minivitals 不会按应有的方式缩小。调整大小后,我如何才能使布局看起来像我以该大小打开程序时的样子?

程序以正常大小打开时的屏幕截图:

正常尺寸开始

以正常尺寸打开后收缩(注意浓度条被推离屏幕底部):

在此处输入图像描述

以较小的尺寸打开:

在此处输入图像描述

以较小的尺寸打开然后扩大:

在此处输入图像描述

在调整大小之间重新启动具有预期的效果,除了需要重新启动部分。

public class BarsView extends ViewPart {
    private PageBook book;
    public void createPartControl(Composite parent) {   
        book = new PageBook(parent, SWT.NONE);
        book.setLayout(new FillLayout());
        Composite page = new BarsPageView(book, view);
        book.showPage(page);
    }
    private class BarsPageView extends Composite {
        public BarsPageView(Composite parent, GameView view) {
        super(parent, SWT.NONE);
        this.setLayout(new GridLayout(3, false));

        // This is a wrapper around a StyledText
        entry = new StormFrontEntry(this, view);
        GridData entryData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
        entryData.heightHint = 22;
        entry.getWidget().setLayoutData(entryData); // getWidget() returns the StyledText

        // This is a Composite containing a Canvas
        status = new StormFrontStatus(this, view);
        status.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));

        // This is defined below                
        GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2);
        compassData.heightHint = 64;
        compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
        compass.setLayoutData(compassData);

        minivitals = new StormFrontDialogControl(this, SWT.NONE);
        GridData mvData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
        minivitals.setLayoutData(mvData);
    }
}

public class WarlockCompass extends Canvas {
    public WarlockCompass (final Composite parent, int style, CompassTheme theme, GridData layoutData) {
        super(parent, style);
        addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                drawCompass(e.gc);
            }
        });
        parent.addListener(SWT.Resize, new Listener() {
            @Override
            public void handleEvent(Event event) {
                // I cut out the calculations for this
                layoutData.heightHint = height;
                WarlockCompass.this.setSize(width, height);
            }
        });
    }
    private void drawCompass (GC gc) {
        // Cut out the calculations to scale the image to fix the canvas
        gc.drawImage(scaledImage, 0, 0);
    }
}
4

1 回答 1

0
    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

本来应该:

    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

更改该标志使其正确调整大小。

于 2013-02-14T22:48:31.497 回答