简体   繁体   中英

Custom Compose Arrangement to add extra spacing at beginning and end of a LazyRow/LazyColumn

How can I create a custom Arrangement for LazyRow to add additional spacing at beginning and end, but have even spacing in between?

Start|< more space> Item 1 Item 2 Last Item |End

object CustomArrangement : Arrangement.Horizontal {
  override fun Density.arrange(
    totalSize: Int,
    sizes: IntArray,
    layoutDirection: LayoutDirection,
    outPositions: IntArray
  ) {

  }
}

https://developer.android.com/jetpack/compose/lists#custom-arrangements

It is not the answer to your question, but you can achieve the same adding a header and footer items, or using a horizontal PaddingValues .

A simple LazyRow :

LazyRow(
    horizontalArrangement =   Arrangement.spacedBy(8.dp),
    contentPadding = PaddingValues(horizontal = 50.dp),
    modifier= Modifier.fillMaxSize(),
) {

    items(itemsList) {
        Text("Item is $it")
    }
}

or something like:

LazyRow(
    horizontalArrangement =   Arrangement.spacedBy(8.dp),
    modifier= Modifier.fillMaxSize()
) {
    //Header
    item(){
        Spacer(modifier = Modifier.width(40.dp))
    }
    items(itemsList) {
        Text("Item is $it")
    }
    //Footer
    item(){
        Spacer(modifier = Modifier.width(40.dp))
    }
}

在此处输入图像描述

Maybe you can get the effect you're looking for with one of the paramenters for LazyRow: contentPadding = PaddingValues(horizontal = "your_value")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM