我正在将应用程序迁移到 Jetpack Compose,并且在查看/撰写混合屏幕上遇到以下情况:
我的问题是:我可以做一些事情让两个部分一起工作吗?即:当我滚动 LazyColumn 时,包含它的 CoordinatorLayout 将使其顶部栏折叠/展开。
我将 Compose 与现有片段一起使用。我在 xml 中的结构
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView />
<MaterialToolbar />
</CollapsingToolbarLayout>
</AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.compose.ui.platform.ComposeView
android:id="@+id/composeContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.core.widget.NestedScrollView>
</CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
在 ComposeView 中,我使用 LazyColum,它因日志而崩溃
java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like ScrollableContainer and LazyColumn is not allowed. If you want to add a header before the list of items please take a look on LazyColumn component which has a DSL api which allows to first add a header via item() function and then …Run Code Online (Sandbox Code Playgroud) android android-collapsingtoolbarlayout android-jetpack-compose
我正在尝试实现 CollapsingToolbar,Compose但我通过互联网找到的示例无法满足我的需求。我曾经使用 xml 并且相同的布局是:
-AppBarLayout
-CollapsingToolbarLayout
-ConstraintLayout
-ImageView(parallax, centerCrop)
-Toolbar
-NestedScrollView
-FloatingButton (anchorGravity="bottom|end")
-Button(sticky)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多事情,但困难的是拥有FloatingButton(可以是任何其他视图,而不是特别的FAB)。
演示:
我做的效果parallax如下:
Box(
modifier = Modifier.graphicsLayer {
translationy = -scroll.value.toFloat() / 2f
alpha = (-1f / headerHeightPx) * scroll.value + 1
}
) { Image... }
Run Code Online (Sandbox Code Playgroud)
我还找到了,Compose Collapsing Toolbar library但如果可能的话,我宁愿不使用任何库。
我已经看到有一个 Material3 有一个TopAppBar,也许它会起作用。
我也尝试过该Material3库,但没有按预期工作,因为我的行为打破了它应有的样子。
我的想法是创建一个Boxor 因为我想要高程 aSurface并在其上包含在Icon和 theImage以及 center内Box。
我创建了一个简单的图像来描述我的想法,也许这是一个很好的开始方式。 …