相关疑难解决方法(0)

Jetpack Compose:如何将 LazyVerticalGrid 放入可滚动列中?

当尝试将 a 放入可滚动LazyVerticalGrid内容时,出现以下错误: Column

java.lang.IllegalStateException:不允许在同一方向嵌套可滚动布局,例如 LazyColumn 和 Column(Modifier.verticalScroll())。如果您想在项目列表之前添加标题,请查看 LazyColumn 组件,该组件具有 DSL api,允许首先通过 item() 函数添加标题,然后通过 items() 添加项目列表。

我不是在制作传统的列表,我只是有很多太大而无法在屏幕上显示的元素。因此,我希望该列滚动,以便我可以看到所有元素。这是我的代码:

@ExperimentalFoundationApi
@Composable
fun ProfileComposable(id: String?) {
    val viewModel: ProfileViewModel = viewModel()
    if (id != null) {
        viewModel.getProfile(id)
        val profile = viewModel.profile.value
        val scrollState = rememberScrollState()
        if (profile != null) {
            Column(modifier = Modifier
                .fillMaxWidth()
                .fillMaxHeight()
                .verticalScroll(scrollState)) {
                Row() {
                    ProfilePic(profile.getImgUrl(), profile.name)
                    Column(Modifier.padding(16.dp)) {
                        ProfileName(profile.name)
                        Stats(profile.stats) //      <--------------- the offending composable
                    }
                }
                Sprites(sprites = profile.sprites)
                TextStat(profile.id.toString(), "Pokemon Number")
                TextStat(profile.species.name, "Species") …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose

50
推荐指数
5
解决办法
3万
查看次数

如何在 jetpack compose 中使用静态值创建可扩展列表视图

我创建了具有静态值的 Kotlin 代码:

我想知道如何使用 jetpack compose 创建相同的内容?我不知道

代码:

       class TestApp : AppCompatActivity() {
    
        var listAdapter: ExpandableListAdapter? = null
        var expListView: ExpandableListView? = null
        var listDataHeader: MutableList<String>? = null
        var listDataChild: HashMap<String, List<String>>? = null
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
            expListView = findViewById<View>(R.id.lvExp) as ExpandableListView
            prepareListData()
            listAdapter = ExpandableListAdapter(this, listDataHeader, listDataChild)
            expListView!!.setAdapter(listAdapter)
    
        }
        private fun prepareListData() {
        listDataHeader = ArrayList()
        listDataChild = HashMap()
        listDataHeader?.add(getString(R.string.q_1))
        val on_0: MutableList<String> = ArrayList()
        on_0.add(getString(R.string.faq_d_0))
        listDataChild!![listDataHeader!![0]] = on_0
}
    }
Run Code Online (Sandbox Code Playgroud)

android expandablelistview android-jetpack-compose

11
推荐指数
1
解决办法
7136
查看次数

在Jetpack Compose中使用lazyColum列里面有错误

我有一个lazyColumn,我想在列中使用它,但出现以下错误并且应用程序崩溃:

不允许在相同方向的布局中嵌套可滚动的布局,例如 LazyColumn 和 Column(Modifier.verticalScroll())。如果您想在项目列表之前添加标题,请查看 LazyColumn 组件,该组件具有 DSL api,允许首先通过 item() 函数添加标题,然后通过 items() 添加项目列表

lazyColumn 代码,我在此代码中有一个列表:


@Composable
fun UpScreenSection(
    modifier: Modifier,
    state: ProfileState,
    viewModel: ProfileViewModel
) {
    Spacer(modifier = Modifier.size(24.dp))

    Column(
        modifier = modifier
            .fillMaxSize()
            .padding(24.dp)
    ) {
        if (!state.items.isNullOrEmpty()) {
            Box(
                modifier = modifier
                    .fillMaxSize()
            ) {
                LazyColumn(modifier = modifier.fillMaxSize()) {
                    items(state.items) { item ->
                        ProfileListItems(item = item, onItemClick = {
                            //TODO Navigate to specific screen
                            when (it.id) {
                                1 -> {
                                }
                                2 -> {
                                }
                                3 -> { …
Run Code Online (Sandbox Code Playgroud)

android android-compose-textfield

8
推荐指数
1
解决办法
8916
查看次数

如何在 Jetpack Compose 的 LazyColumn/LazyRow 中禁用和启用滚动?

我想在LazyColumn.

本身似乎没有任何相关功能LazyListState或相关参数LazyColumn。如何在 Compose 中实现这一目标?

android kotlin android-jetpack-compose

7
推荐指数
3
解决办法
1614
查看次数

如何在 Jetpack Compose 中使用 LazyColumn 构建树?

在我的 jetpack-compose 应用程序中,我正在构建一个注释树,其中顶层和叶子是列表,最好使用LazyColumn.

其形式如下:

List<CommentNode>
...
CommentNode: {
  content: String
  children: List<CommentNode>
}
Run Code Online (Sandbox Code Playgroud)
@Composable
fun Nodes(nodes: List<CommentNode>) {
  LazyColumn {
    items(nodes) { node -> 
      Node(node)
    }
  }
}

@Composable
fun Node(node: CommentNode) {
  LazyColumn {
    item {
      Text(node.content)
    }
    item {
      Nodes(node.children)
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在顶层,LazyColumn可以工作,但似乎我必须用于Column叶子,否则我会遇到无法解释的崩溃:

03-29 14:36:38.792  1658  6241 W ActivityTaskManager:   Force finishing activity com.jerboa/.MainActivity 
03-29 14:36:38.902  1658  3033 I WindowManager: WIN DEATH: Window{d3b902b u0 com.jerboa/com.jerboa.MainActivity}                      
03-29 14:36:38.902  1658  3033 W InputManager-JNI: Input …
Run Code Online (Sandbox Code Playgroud)

android android-jetpack-compose

7
推荐指数
1
解决办法
2586
查看次数

Jetpack compose 中 [NestedScrollView + RecyclerView] 或 [Nested RecyclerView (Recycler inside another recycler) 的等价物是什么

我想在 Jetpack compose 中创建以下布局。 在此处输入图片说明

我试过在一个垂直可滚动的 Box 内创建两个列表,但这是不可能的,因为我收到了这个错误:“java.lang.IllegalStateException:不允许在相同方向的布局中嵌套滚动,如 ScrollableContainer 和 LazyColumn。如果你想添加项目列表之前的标题请查看 LazyColumn 组件,该组件具有 DSL api,允许首先通过 item() 函数添加标题,然后通过 items() 添加项目列表。”

我尝试使用以下代码在父列表中创建两个不同的列表,但这也不起作用。

@Composable
fun MainList() {
    LazyColumn() {
        
        item {
            /* LazyRow code here */
        }
        
        item {
            /* LazyColumn code here */
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我不知道我还能尝试在同一个活动上实现两个列表(一个垂直和一个水平)并保持活动垂直滚动。

android list android-recyclerview android-jetpack-compose

6
推荐指数
1
解决办法
2282
查看次数