https://kotlinlang.org logo
Title
d

Dirk Hoffmann

03/07/2021, 11:04 AM
I have a TabRow like so:
Column(modifier) {
        TabRow(selectedTabIndex = activeTab()) {
            Tab(selected = activeTab() == 0, onClick = { activeTab(0) }, enabled = true) {
                Text("Tab 1", Modifier.padding(3.dp), textAlign = TextAlign.Center)
            }
            Tab(selected = activeTab() == 1, onClick = { activeTab(1) }, enabled = true) {
                Text("Search: Result", Modifier.padding(3.dp), textAlign = TextAlign.Center)
            }
            Tab(selected = activeTab() == 2, onClick = { activeTab(2) }, enabled = true) {
                Text("Tab 3", Modifier.padding(3.dp), textAlign = TextAlign.Center)
            }
        }
no matter what I try, I don't get the Tab Texts vertically centered. Isn't TabRow missing a "verticalAligment" parameter???
g

Glenn Martin

03/07/2021, 12:22 PM
I'm having a similar issue but with a bottom header and just for a row, so I gave up and just have it some
top
padding and it did the trick
i

Igor Demin

03/07/2021, 12:45 PM
Just fix the
height
and add
fillMaxHeight()
to every
Tab
Column {
    TabRow(selectedTabIndex = 0, Modifier.height(48.dp)) {
        Tab(selected = true, onClick = { }, enabled = true, modifier = Modifier.fillMaxHeight()) {
            Text("Tab 1", Modifier.padding(3.dp), textAlign = TextAlign.Center)
        }
        Tab(selected = false, onClick = { }, enabled = true, modifier = Modifier.fillMaxHeight()) {
            Text("Search: Result", Modifier.padding(3.dp), textAlign = TextAlign.Center)
        }
        Tab(selected = false, onClick = { }, enabled = true, modifier = Modifier.fillMaxHeight()) {
            Text("Tab 3", Modifier.padding(3.dp), textAlign = TextAlign.Center)
        }
    }
}
If you need a dynamic height (height is determined by `TabRow`'s content), you should use something like this
CustomTabRow(selectedTabIndex = 0, Modifier.height(IntrinsicSize.Min))
Where
CustomTabRow
is a copy of
TabRow
, but without `SubcomposeLayout`(`SubcomposeLayout`doesn't support IntrinsicSize)
1
j

Joe Jensen

03/19/2021, 4:24 PM
Will
SubcomposeLayout
ever support intrinsics ?
i

Igor Demin

03/19/2021, 4:30 PM
j

Joe Jensen

03/19/2021, 4:32 PM
Thanks!