Kar*_*lis 5 android bottom-sheet android-jetpack-compose
我有一个ModalBottomSheet
,里面有一个LazyColumn
项目列表。当我快速向上或向下滚动(即快速滚动)该LazyColumn
内容时,底部工作表会短暂地从底部或顶部分离(取决于滚动方向)。我想删除这种行为,以便我的ModalBottomSheet
牢牢地粘在底部和顶部(它是全屏底部工作表)。
有谁知道如何实现这一目标?:)
我正在使用此依赖项中当前最新的底表:
androidx.compose.material3:material3-android:1.2.0-alpha02
我删除了很多内容代码,但一般来说底部工作表内容是这样的:
@Composable
fun BottomSheetContent() {
Column(modifier = modifier.fillMaxSize()) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
.verticalScroll(rememberScrollState())
.weight(1f)
) {
GenresSection(
selectedGenres = selectedGenres,
)
}
ResetAllAndApplyFilterButtonsRow(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp, horizontal = 16.dp)
)
}
}
@Composable
fun GenresSection(
selectedGenres: List<Genre>,
modifier: Modifier = Modifier,
) {
LazyColumn(
modifier = modifier.height(400.dp),
) {
items(selectedGenres) { genre ->
GenreChoiceRow(
text = genre.name,
modifier = Modifier.animateItemPlacement()
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了一种人工智能建议的附加nestedScrollConnection的方法,其中我调整了onPostFling行为以返回0速度,因此在向父级滑动后不会返回任何速度,但这没有帮助。这是由 phind.com AI 建议的:
val nestedScrollConnection = remember {
object : NestedScrollConnection {
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
return super.onPostFling(consumed, Velocity.ZERO)
}
override suspend fun onPreFling(available: Velocity): Velocity {
return super.onPreFling(available)
}
}
}
LazyColumn(
modifier = Modifier.nestedScroll(nestedScrollConnection)
) {
// Your scrollable content here
}
Run Code Online (Sandbox Code Playgroud)
小智 0
我试试这个
LazyVerticalGrid(columns = GridCells.Fixed(2), flingBehavior = flingBehavior) {
videoTempState.value.pagConfigBean?.videoTempList?.let { it ->
items(it, key = { it?.uuid ?: "" }) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
) {
AndroidView(factory = {
PAGView(it)
}, update = {
})
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
重点是设置fling
private val flingBehavior = object : FlingBehavior {
override suspend fun ScrollScope.performFling(initialVelocity: Float): Float {
return 0F
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
780 次 |
最近记录: |