跳到内容
CrossFly 是 100% 开源在 GitHub 关注我们
CrossFlyCrossFly
开始使用
全部示例
配方导航浮层71 行 · 1 个文件

Bottom sheet with a fixed footer

BottomSheet already gives you the header, the grabber, the close button and a footer that floats over the scroll. You only fill body().

它展示了什么

A bottom sheet with a header and a footer that stay put while the middle scrolls.

在你的机器上运行

每个示例都是普通的 Window,启动器只需要它的名字。

gradlew lwjgl3:run --args="classname dev.cf.recipe.R04Sheet"
修改它

Java 是提前编译的,浏览器无法自行重建你的修改 —— 这里的代码在发布前已由 TeaVM 转成 JavaScript。把文件复制到项目里,它在四个平台上原样运行;上面那条命令就是全部准备工作。

正在此处运行CrossFly 0.1.32
正在启动应用…

由 TeaVM 编译为 JavaScript —— 是同一份代码,不是录像。 · 全部示例

它用到了什么

本示例触及的框架类型。带链接的有参考页。

BottomSheetButtonComponentDebugGridLayoutStylesWidgets

源码

完整无删减。这就是那个文件,不是片段。

原始
dev/cf/recipe/R04Sheet.java
package dev.cf.recipe;

import dev.cf.Tones;

import dev.crossfly.ui.*;
import dev.crossfly.ui.color.*;
import dev.crossfly.ui.graphics.*;
import dev.crossfly.ui.layout.*;
import dev.crossfly.ui.style.*;

import static dev.crossfly.ui.Widgets.*;

/**
 * A bottom sheet with a header and a footer that stay put while the middle scrolls.
 */
public class R04Sheet extends Recipe
{
   public String title()
   {
      return "Bottom sheet with a fixed footer";
   }

   public String note()
   {
      return "BottomSheet already gives you the header, the grabber, the close button and a footer"
         + " that floats over the scroll. You only fill body().";
   }

   public void build(Component body) throws Exception
   {
      Button abrir = Tones.action("Open the sheet");
      abrir.testTag("recipe.open");
      abrir.onAction(c -> abrirSheet());
      body.add(LAY_AUTO, abrir);
   }

   private void abrirSheet()
   {
      try
      {
         // The kicker is the small upper-case label above the title.
         final BottomSheet sheet = new BottomSheet("FILTER", "Choose a segment");
         sheet.maxHeightRatio(.7f);

         for (int i = 1; i <= 20; i++)
         {
            // A tonal pill per segment: twenty identical grey lines is a list nobody can aim at.
            Component linha = new Component();
            linha.setLayout(new GridLayout(Position.START, Position.CENTER));
            linha.add(LAY_AUTO, LAY_AUTO, Tones.tile(0xE574, Tones.cycle(i)),
               outgap(label("Segment " + i, 1f, false, Styles.textColor, Position.START),
                  .6f, 0, 0, 0));
            sheet.body()
               .add(LAY_AUTO, outgap(linha, 0, .3f, 0, .3f));
         }

         // The footer does NOT go into the body: it floats over the scroll and stays reachable with
         // the list at its end — which is why it has an API of its own.
         Button aplicar = Tones.action("Apply");
         aplicar.onAction(c -> sheet.hide());
         sheet.footer(aplicar);

         sheet.show();
      }
      catch (Exception e)
      {
         dev.crossfly.util.Debug.handle(e);
      }
   }
}
给 AI 助手

本页的机器可读版本,让模型直接读取示例集,而不是猜测 API。

本示例(JSON)本示例(Markdown)
上一个Switching skins下一个Listing: cards or table