Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose ClipToPadding

I understand that i can add padding to a widget like so

LazyColumn(
   modifier = Modifier.padding(0.dp, 0.dp, 0.dp, 10.dp),
   content = {
        items(items.size) { index ->
            EmergencyContactComposeItem(emergencyContact = items[index])
        }
    }
)

But how do i produce the same result as "clipToPadding=false"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:clipToPadding="false"
    android:paddingBottom="25dp">

Where the view / widget will not clip the padding, but still enforce the bounds?

like image 956
Brandon Avatar asked Mar 02 '21 08:03

Brandon


2 Answers

Try content padding like below:

LazyColumn(
    contentPadding = PaddingValues(bottom=10.dp),
){

    items(items.size) { index ->
        EmergencyContactComposeItem(emergencyContact = items[index])
    }
}
like image 197
Sponge Bob Avatar answered Oct 24 '22 00:10

Sponge Bob


LazyColumn takes contentPadding to implement clipToPadding. You can use it in three ways.

First One: If you want to add same content padding in all directions then use:

LazyColumn(
   contentPadding = PaddingValues(all = 16.dp)
) {
    items(items.size) { index ->
        EmergencyContactComposeItem(emergencyContact = items[index])
    }
}

Second One: If you want to add same content padding in horizontal(start and end) or in vertical(top and bottom) then use:

LazyColumn(
   contentPadding = PaddingValues(horizontal = 16.dp, vertical = 10.dp)
) {
    items(items.size) { index ->
        EmergencyContactComposeItem(emergencyContact = items[index])
    }
}

Third One: If you want to add different content padding in all directions or if you want to add in some directions then use:

LazyColumn(
   contentPadding = PaddingValues(start = 5.dp, top = 10.dp, end = 8.dp, bottom = 6.dp)
) {
    items(items.size) { index ->
        EmergencyContactComposeItem(emergencyContact = items[index])
    }
}
like image 20
Avijit Karmakar Avatar answered Oct 23 '22 23:10

Avijit Karmakar