Wie man einen Kopfball versteckt, wenn man in Kotlin nach unten scrollen

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie man einen Kopfball versteckt, wenn man in Kotlin nach unten scrollen

by Anonymous » 12 Mar 2025, 13:38

Ich habe einen Header, der im Grunde genommen ein abgerundetes Rechteck mit etwas Text und zwei Tasten und einem Hintergrundbild hinter dem Rechteck ist, das sich ganz oben erstreckt. Ich möchte, dass der Header verschwindet, wenn der Benutzer beim Scrollen nach unten scrollt und wieder auftaucht. Aber der Header erfrischt sich mit jeder Registerkartenänderung. < /P>
Hat jemand eine Idee, was zu tun ist, bitte? Ich habe versucht, den Header auch in eine separate Datei zu wechseln.
Danke im Voraus.

Code: Select all

@Composable
fun MyApp() {
val tabs = listOf("Home", "Contact")
var selectedTab by remember { mutableStateOf(0) }
var headerVisible by remember { mutableStateOf(true) }  // Control header visibility

val animatedAlpha by animateFloatAsState(if (headerVisible) 1f else 0f)

Column {
// ✅ Moved Header to a Separate Function (Prevents Refresh)
if (animatedAlpha > 0f) {
Header()
}

// Tabs
TabRow(
selectedTabIndex = selectedTab,
backgroundColor = Color.White, // ✅ Background color of TabRow
modifier = Modifier
.fillMaxWidth()
.offset(y = 0.dp) // ✅ Keeps it in place
.zIndex(1f) // ✅ Ensures tabs stay above other components if needed
) {
tabs.forEachIndexed { index, title ->
Tab(
selected = selectedTab == index,
onClick = { selectedTab = index },
selectedContentColor = Color(0xff1f68da), // ✅ Color when selected
unselectedContentColor = Color.Gray, // ✅ Color when not selected
text = {
Text(
text = title,
fontFamily = customFontFamily,
fontWeight = FontWeight.Normal,
color = if (selectedTab == index) Color(0xff1f68da) else Color.Gray
)
}
)
}
}

// WebView Content Based on Selected Tab
when (selectedTab) {
0 -> HomeView { scrollDiff -> headerVisible = scrollDiff  ContactView { scrollDiff -> headerVisible = scrollDiff  Unit) {
WebViewPage(url = "https://www.google.com”, onScroll = onScroll)
}


Top