【问题标题】:Scrolling issue on Vaadin 21 and ApplicationLayoutVaadin 21 和 ApplicationLayout 的滚动问题
【发布时间】:2021-11-27 17:05:16
【问题描述】:

我的应用程序布局和需要滚动的视图有一个奇怪的问题:

如果我使用默认的应用程序布局创建应用程序,则抽屉开关位于顶部,并且我添加了一个具有全尺寸的 VerticalLayout 作为视图,一切都按预期工作。但是,如果垂直内容超过了浏览器窗口的高度(即使我将此内容放入滚动条),整个视图都会滚动并消失在切换按钮的后面,直到达到切换按钮的高度,然后滚动停止。 setHeight(100, Unit.Percentage) 似乎没有考虑切换的高度。

有人有类似的问题吗?

编辑

将以下代码作为视图放入 AppLayout 并在您的移动设备上打开它,例如iPhone,您将看到垂直滚动条:

@Route(value = "application/test", layout = ApplicationLayout.class)
@PageTitle("Test")
@RolesAllowed({"ROLE_NEWSLETTER_ADMIN", "ROLE_ORGANIZATION_ADMIN"})
public class TestView extends VerticalLayout implements BeforeEnterObserver {

    private MenuBar menu;
    private Grid<Person> grid;
    private Label footerLabel;

    public TestView() {
        this.setSizeFull();

        menu = new MenuBar();
        menu.addItem("New");
        menu.addItem("Edit");
        menu.addItem("Delete");
        this.add(menu);

        grid = new Grid<>(Person.class);
        this.add(grid);
        this.expand(grid);
        
        footerLabel = new Label("Number of objetcs: #");
        this.add(footerLabel);
    }

    @Override
    public void beforeEnter(BeforeEnterEvent beforeEnterEvent) {

    }
}

应用布局:

public class ApplicationLayout extends AppLayout implements AfterNavigationObserver {

    private ApplicationService applicationService;
    private H1 headerTitle;

    public ApplicationLayout(ApplicationService applicationService) {
        this.applicationService = applicationService;

        createHeader();
        createDrawer();

        this.setPrimarySection(Section.DRAWER);
    }

    private void createHeader() {
        // Define the header
        HorizontalLayout header = new Header(new H1("Header"));
        addToNavbar(header);
    }
    
    private void createDrawer() {
        ....
    }
}

【问题讨论】:

  • 请添加您尝试过的代码以及失败的原因(例如错误、堆栈跟踪、日志等),以便我们对其进行改进。
  • @cfrick:请看修改后的帖子

标签: vaadin vaadin-flow vaadin21


【解决方案1】:

setHeight(100, Unit.Percentage) 不考虑切换的高度。

正确。 100% 是视口的大小。所以如果你有例如以下

VerticalLayout vLayout = new VerticalLayout();
Button button = new Button();
button.setHeight(50, Unit.Pixels);
HorizontalLayout hLayout = new HorizontalLayout();
hLayout.setHeight(100, Unit.Percentage);
vLayout.add(button,hLayout);

这将产生 vLayout 高度大于视口高度和滚动条出现的东西。相反,您应该这样做。

VerticalLayout vLayout = new VerticalLayout();
Button button = new Button();
button.setHeight(50, Unit.Pixels);
HorizontalLayout hLayout = new HorizontalLayout();
hLayout.setHeight(200, Unit.Pixels);
vLayout.add(button,hLayout);
vLayout.expand(hLayout); // or vLayout.setFlexGrow(1.0d, hLayout);

【讨论】:

  • 您好,如果您有嵌套布局,这是可行的,但在我的情况下,您创建了一个由垂直布局组成的“视图”,并将其“放入”到 ApplicationLayout 中。我已经通过示例代码扩展了我的帖子以重现该问题。弗洛里安
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 2015-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多