2016-05-20 4 views
1

私はborderLayout centerを使用しましたが、画面の高さではなくコンポーネントの中心に位置しています。だから私はBorderLayout.CENTER_BEHAVIOR_CENTERを使用しました。コンポーネントはフォームの中央に配置されますが、全体の画面サイズを取る必要があるアニメーションがありますが、コンポーネントのサイズのみを使用しています。コンポーネントをborderlayout - codenameoneに中心合わせする

メニューアニメーション:

private void menuAnimation(Container c) { 
    int w = Display.getInstance().getDisplayWidth(); 
    int h = Display.getInstance().getDisplayHeight(); 
    int[] positionX = {-100, w/2, w + 100, w + 100, w + 100, w/2, -100, -100}; 
    int[] positionY = {-100, -100, -100, h/2, h + 100, h + 100, h + 100, h/2}; 
    for (int iter = 0; iter < c.getComponentCount(); iter++) { 
     Component cmp = c.getComponentAt(iter); 
     cmp.setY(positionY[iter % positionY.length]); 
     cmp.setX(positionX[iter % positionX.length]); 
    } 
} 

コード:

//f.setLayout(new FlowLayout(Component.CENTER, Component.CENTER)); 
    f.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER)); 

    Container menuContainerGroup = new Container(new BoxLayout(BoxLayout.Y_AXIS)); 
    f.add(menuContainerGroup); 

    TableLayout tl = new TableLayout(3, 3); 
    Container menuContainer = new Container(tl); 

    menuContainerGroup.add(menuContainer); 

    Image round = theme.getImage("loginBg.png").scaledWidth(imgWidth/3 - 10); 

    Label menuIcon = new Label(); 
    menuIcon.setUIID("menuButton"); 

    Button menuIcon1 = new Button(round); 
    menuIcon1.setUIID("menuButton"); 
    menuIcon1.addActionListener((e) -> { 
     menuAnimation(menuContainer); 
     menuContainer.animateUnlayoutAndWait(600, 20); 
     showForm("", null); 

    }); 

    Label menuIcon2 = new Label(); 
    menuIcon2.setUIID("menuButton"); 

    Button menuIcon3 = new Button(round); 
    menuIcon3.setUIID("menuButton"); 
    menuIcon3.addActionListener((e) -> { 
     menuAnimation(menuContainer); 
     menuContainer.animateUnlayoutAndWait(600, 20); 
     showForm("", null); 
    }); 

    Button menuIcon4 = new Button("Sign Out"); 
    menuIcon4.setUIID("menuButton"); 
    menuIcon4.getAllStyles().setFgColor(0xff7800); 
    menuIcon4.getAllStyles().setAlignment(Component.CENTER); 
    menuIcon4.addActionListener((e) -> { 
     menuAnimation(menuContainer); 
     menuContainer.animateUnlayoutAndWait(600, 20); 
     showForm("", null); 
    }); 

    Button menuIcon5 = new Button(round); 
    menuIcon5.setUIID("menuButton"); 
    menuIcon5.addActionListener((e) -> { 
     menuAnimation(menuContainer); 
     menuContainer.animateUnlayoutAndWait(600, 20); 
     showForm("", null); 
    }); 

    Label menuIcon6 = new Label(); 
    menuIcon6.setUIID("menuButton"); 

    Button menuIcon7 = new Button(round); 
    menuIcon7.setUIID("menuButton"); 
    menuIcon7.addActionListener((e) -> { 
     menuAnimation(menuContainer); 
     menuContainer.animateUnlayoutAndWait(600, 20); 
     showForm("", null); 
    }); 

    Label menuIcon8 = new Label(); 
    menuIcon8.setUIID("menuButton"); 

    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon1); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon2); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon3); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon4); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon5); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon6); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon7); 
    menuContainer.add(tl.createConstraint().widthPercentage(33), menuIcon8); 
    f.revalidate(); 

答えて

0

成分が境界配置位置内にある容器内に収容されているため、これが起こっている理由です。したがって、アニメーションを作成するときには、親コンテナの範囲外にレンダリングして、親コンテナをクリップします。

事実の後に中心レイアウトの制約を設定し、制約効果と要素の位置の両方をアニメートするanimateLayoutHierarchyを使用することが考えられます。

+0

私は解決部分を理解していません。申し訳ありません –

+0

センターの制約を使用しないと、UIが画面全体に拡大され、クリッピングが正しく機能します。新しいレイアウト制約を適用し、animateLayoutHierarchyを呼び出すと、特定のコンポーネントではなく階層全体がアニメーション化され、親コンテナが徐々に縮小されてアニメーションが表示されるようになります。 –

+0

私は中心の拘束を削除しました。しかし、まだアニメーションはコンポーネント内にしかありません。また、画面の中央にコンポーネントグループ全体を配置する必要もあります。あなたの答えで私のコードを修正してください。 –

関連する問題