I want to add dynamic tab items. in a scrollable way, not fixed tabs
I followed this example here
But after I implement the same, still the tabs fixed, what I want is to show the whote text of the tab (Not fixed size tab), and the tabs must be scrollable like the following image
I tried to make the TabRaw scrollable as the following:
TabRow(
selectedTabIndex = pagerState.currentPage,
backgroundColor = Color.Transparent,
modifier = Modifier
.fillMaxWidth()
.padding(MaterialTheme.spacing._20sdp)
.horizontalScroll(scrollableState)
.height(32.dp),
contentColor = colorResource(id = R.color.primary)
)
But it throws IllegalArgumentException, Because I'm including it in a ConstraintLayout
I only used ScrollableTabRow instead of TabRow
Related
LazyColumn in Jetpack Compose works fine with Scaffold and its inner padding according to this link. but when I try to use it inside a Fragment, it's items cut off by Toolbar and BottomNavigationView.
should I calculate inner padding manually depending on Toolbar and BottomNavigationViewsize or is there a better solution?
here's the structure. items of lazyColumn are colorful.
as you can see blue item is cut off.
update:
I realized that this behavior is because root of activity is a CoordinatorLayout and my container has appbar_scrolling_view_behavior. I tried this, but it didn't work.
I'm not sure if this would help, but you can try adding the height of the Bottom Navigation view as a bottom content padding to the LazyColumn or to a transparent widget inside another item{…} scope.
as a content padding
LazyColumn(
modifier = Modifier
.fillMaxSize(),
contentPadding = PaddingValues(bottom = <Bottom navigation height>)
) {…}
or as another item scope
LazyColumn(
modifier = Modifier
.fillMaxSize()
) {
items (..) {…}
item {
Box(
modifier = Modifier.height(<Bottom navigation view height>)
)
}
}
I have an Add Shopping List item Jetpack Compose screen which contains several TextField inputs and an image container at the bottom. The screen overflows at the bottom and is cut off. How can I scroll the screen?
Add Modifier.scrollable(..) to the container that you wish to make scrollable.
Code would be something like this:
val scrollState = rememberScrollState()
...
Box( // or whatever your parent composable is
modifier = Modifier
.scrollable(state = scrollState, orientation = Orientation.Vertical)
) {
...
}
Of course, there are other Modifier methods for making composables scrollable that might fit better for your case.
I have implemented HorizontalPager with TabRow in my project. My HorizontalPager uses default fling behaviour from PagerDefaults.flingBehavior(state). I have not overridden the fling behavior.
This is how the code looks like:
val pagerState = rememberPagerState()
HorizontalPager(
count = profileState.tabs.size,
state = pagerState
) {..grid item..}
I have to scroll very hard to scroll between the pager items. I want the pager to scroll to next/previous screen on even slight scroll.
After debugging and logging, I found that initialVelocity in performFling method is coming out to be -0.0 (same for left and right fling) all the time for some reason.
You can use (with Accompanist version: accompanist-pager:0.24.8-beta):
HorizontalPager(
count = 3,
state = pagerState,
verticalAlignment = Alignment.Top,
modifier = Modifier.fillMaxSize()
)
In my case, there was a horizontal scrollable Row in the pager item. Make it unscrollable.
I want to implement this ui.
How can i overlap post list item on each other in android jetpack compose?
If you're using a Column or a LazyList to display the items, you can use the verticalArrangement parameters with a negative spacedBy space.
LazyColumn(
verticalArrangement = Arrangement.spacedBy((-32).dp)
) {
// Put the items to overlap here
}
spacedBy() doc
Use Box to put one element on top of another.
Also, read official documentation here
You can use Box
sample :
Box(modifier = Modifier.fillMaxSize()) {
Image(modifier = Modifier.fillMaxSize()) {} //Image1
Image(modifier = Modifier.fillMaxSize()) {} //Image2
}
In the above example, Image2 will cover the Box's maxSize. Image1 will be beneath Image2.
Adding to Bagadeshkumar R's answer, you can place Spacer with height that is spacer(modifier = Modifier.height(8.dp)), attribute between image 1 and 2, for image 1 to be partially visible.
Below Image explains specification I want to implements
I want to make Lazy Row scroll item if user drag previous (or next) item to some X_SCROLL_THRESHOLD.
I considered to try Pager in Jetpack compose Sample app Jet Caster, but I want to show quite many items (1788 items) so, I'm not sure Pager approach is proper than using LazyRow.
Is there way to customize LazyRow drag or scroll behavior in android Jetpack Compose?
You can try out Pager Layouts. It's an experimental API currently. Hope Google Devs make it part of the general compose library soon.
Use rememberPagerState to manage initialOffscreenLimit(the no. of pages to retain on either side of the current page).
https://google.github.io/accompanist/pager/
Google Github Samples link - https://github.com/google/accompanist/tree/main/sample/src/main/java/com/google/accompanist/sample/pager
You would need to include this dependency in your app gradle
//Pager
implementation "com.google.accompanist:accompanist-pager:0.18.0"
A simple example
// Display 10 items
val pagerState = rememberPagerState(
pageCount = 10,
initialOffscreenLimit = 2
)
HorizontalPager(state = pagerState) { page ->
// Our page content
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize()
) {
Text(
text = "Item: $page",
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
Text(
text = "Something Else",
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
//Your other composable
}
}
Layout Inspector showcasing the offscreenLimit of 2 items on either side of current page