2016-10-31 36 views
1

我嘗試了snapToGrid,我認爲這可能只是簡單的解決方案,希望用於帶有側滑條目的列表。 但是,如果我禁用了張力拉伸啓用,那麼當行對齊網格時沒有動畫。 有一種方法可以禁用X軸上的拉伸滾動,同時使snapToGrid仍然動畫?沒有使用snapToGrid滾動和tensileDragEnabled設置爲false的動畫

下面的代碼:

public class FormScrollingXY extends Form { 
public FormScrollingXY() { 
    setTitle("FormScrollingXY"); 
    setScrollable(false); 
    setScrollableY(true); 
    setLayout(new BoxLayout(BoxLayout.Y_AXIS)); 
    for (int rowIndex = 0; rowIndex < 50; rowIndex++) { 
     Container containerRow = new Container(new BoxLayout(BoxLayout.X_AXIS)); 
     containerRow.setSnapToGrid(true); 
     containerRow.setScrollableX(true); 
     containerRow.setTensileDragEnabled(false); // bad behaviour 
     for (int columnIndex = 0; columnIndex < 3; columnIndex++) { 
      Container containerColumn = new Container(new FlowLayout()) { 
       @Override 
       protected Dimension calcPreferredSize() { 
        Dimension dimension = new Dimension(super.calcPreferredSize()); 
        dimension.setWidth(containerRow.getWidth()); 
        return dimension; 
       } 
      }; 
      containerColumn.add(new Label((rowIndex + 1) + "/" + (columnIndex + 1))); 
      containerRow.add(containerColumn); 
     } 
     add(containerRow); 
    } 
} 

}

回答

0

這是一個猜測,但嘗試這樣做,看看它是否解決了這個問題:

Container containerRow = new Container(new BoxLayout(BoxLayout.X_AXIS)) { 
    public boolean isScrollableY() { 
     return false; 
    } 
}; 
+0

重載isSrollableY()不會改變任何東西 - 無論如何它都會返回false。 事情是 - 顯然snapToGrid只有在tensileDraghEnabled爲true時才起作用。但我不想在X軸上進行拉伸滾動。我想要的是與動畫對齊的網格行爲。 –

+0

好的,我想我在代碼中看到了問題。對齊網格使用拉伸代碼來執行實際動畫,所以我爲此添加了特殊情況。應該成爲今天更新的一部分。 –

相關問題