使用代号一个组件可以更改其大小,甚至可以对其进行动画处理,这很不错。
但是收缩的Container实例的预期行为是什么,特别是如果它们是可滚动的?
具有一个容器,该容器可在Y轴上滚动,并且内容小于该内容粘贴到顶部的容器。可以拖动容器,并将内容滚动回到容器的顶部。但是,当内容缩小并变得小于容器时,其行为会有些奇怪。
我已经举了一个例子-当点击彩色组件时,它们会扩展。如果再次点击,它们会收缩。一个人可以点击绿色的标签,它会扩展。再次轻按它会缩小,一切都从以前开始。
但是,如果点击一个彩色标签并向下滚动任何数量,然后再次点击以缩小它,则结果视图如下:
只有当人们如此轻轻地拖动滚动容器时,竞争对象才会滚动回到顶部。
我认为这是一个错误。虽然我想知道-当内容缩小到超出滚动容器大小时该怎么办?由于用户可能希望刚刚轻按的组件可以保留在原位置-可以通过某种方式控制滚动行为吗?
这只是一个示例,但我想构建可扩展的“抽屉”组件。
代码如下:
public class FormContentSmallerScrollableContainer extends Form {
private class LabelExpandable extends Label {
boolean expanded = false;
LabelExpandable(String aTitle, int aColor) {
super(aTitle);
getAllStyles().setBgPainter((aGraphics, aRectangle) -> {
aGraphics.setColor(aColor);
aGraphics.fillRoundRect(getX(), getY(), aRectangle.getWidth() - 1, aRectangle.getHeight() - 1, 20, 20);
});
setOpaque(true);
}
@Override
public void pointerReleased(int x, int y) {
super.pointerReleased(x, y);
expanded = !expanded;
setShouldCalcPreferredSize(true);
getParent().animateLayout(400);
}
@Override
protected Dimension calcPreferredSize() {
if (!expanded) {
return super.calcPreferredSize();
}
Dimension dimension = super.calcPreferredSize();
dimension.setHeight(Display.getInstance().getDisplayHeight());
return dimension;
}
}
public FormContentSmallerScrollableContainer() {
super("FormContentSmallerScrollableContainer");
setScrollable(false);
setLayout(new BorderLayout());
add(BorderLayout.NORTH, new Label("The container below is scrollable in the y-axis"));
Container containerScrollable = BoxLayout.encloseY(
new LabelExpandable("LabelExpandable green", 0x00ff00),
new LabelExpandable("LabelExpandable blue", 0x00c0ff));
containerScrollable.setScrollableY(true);
add(BorderLayout.CENTER, containerScrollable);
add(BorderLayout.SOUTH, new Label("The container above is scrollable in the y axis"));
}
}
答案 0 :(得分:1)
当我们将可滚动区域设置为有效的不可滚动区域时,这是长期存在的行为。我们过去曾尝试解决此问题,但找不到正确的方法。您可以就此提出问题,但我并不乐观,因为甚至很难找到解决方法。