You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin开发:TabbedPage能否实现可展开置顶音频播放器?

问题:TabbedPage架构下实现悬浮播放器的展开收起功能

我正在开发一款支持Android和iOS的电台音乐收听应用,当前采用底部菜单的TabbedPage设计。已在MainActivity中创建了一个始终悬浮于所有Tab页面上方的LinearLayout音频播放器视图,希望实现该播放器向上展开与收起的功能(参考效果:音频播放器展开效果)。

核心疑问:TabbedPage是否支持该功能,还是需要更换架构?也考虑过使用不同的LinearLayout或RelativeLayout,附上相关代码如下:

MainActivity代码

ViewGroup contentView = FindViewById<ViewGroup>(Android.Resource.Id.Content);
LinearLayout view = new LinearLayout(this);
view.Orientation = Android.Widget.Orientation.Horizontal;
view.SetBackgroundColor(Android.Graphics.Color.Blue);
view.Background = getDrawableWithRadius();
FrameLayout.LayoutParams parameter = new FrameLayout.LayoutParams((Device.Idiom == TargetIdiom.Tablet ? 60 : LinearLayout.LayoutParams.MatchParent), (Device.Idiom == TargetIdiom.Tablet ? 110 : 160));
parameter.Gravity = GravityFlags.Bottom | GravityFlags.Left;
parameter.BottomMargin = 220;
view.LayoutParameters = parameter;

btnPushPlay = new Android.Widget.ImageButton(this);
btnPushPlay.Click += BtnPushPlay_Click;
btnPushPlay.SetBackgroundColor(Android.Graphics.Color.Transparent);
btnPushPlay.SetImageResource(Resource.Drawable.media_play_green);
view.AddView(btnPushPlay);
lblSong = new TextView(this);
lblSong.TextSize = 18;
lblSong.SetPadding(10, 35, 0, 0);
lblSong.SetTextColor(Android.Graphics.Color.White);
lblSong.Text = "Luister live!";
view.AddView(lblSong);
contentView.AddView(view);

MainPage.xaml代码

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:local="clr-namespace:Kickit_Radio.MenuPages;assembly=Kickit_Radio"
        xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
        xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:local1="clr-namespace:Kickit_Radio.ViewModels"
        android:TabbedPage.ToolbarPlacement="Bottom"
        BarBackgroundColor="#000000"
        BarTextColor="White"
        BackgroundColor="Black"
        x:Class="Kickit_Radio.MainPage"
        NavigationPage.HasNavigationBar="False"
        NavigationPage.HasBackButton="True" SelectedTabColor="Green" UnselectedTabColor="#3184ca">
<TabbedPage.Children>
    <local:Home Title="Home" IconImageSource="home.ico" />
    <local:Nieuws Title="Nieuws" IconImageSource="@drawable/news" />
    <local:Request Title="Request" IconImageSource="@drawable/record" />
    <local:Programma Title="Programma" IconImageSource="@drawable/column" />
    <local:Streams Title="Streams" IconImageSource="@drawable/record" />
    <local:Contact Title="Contact" IconImageSource="@drawable/about"/>
</TabbedPage.Children>
</TabbedPage>

内容的提问来源于stack exchange,提问作者Paul Albers

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 19:35:29