随笔 - 62  文章 - 0  评论 - 114  阅读 - 18万

利用Android 自定义的悬浮播放器实例

在这个工程中最为重要的就是player.xml和ObjectActivity了

首先是播放器这个控件的布局,开始我试着用各种布局都没有能完成我要的效果,因为我用的进度显示是自定义的seekbar似乎它默认会在上下留一定的空白,所以我最后只好用绝对布局了,因为播放器的大小是固定的而且它不依赖于父控件的大小所以这种布局效果还不错

复制代码
player.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:id="@+id/slidingDrawer1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:baselineAligned="false"
        android:orientation="horizontal" >

        <AbsoluteLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_x="0dp"
                android:layout_y="8dp" >

                <LinearLayout
                    android:id="@+id/content"
                    android:layout_width="wrap_content"
                    android:layout_height="52dp"
                    android:background="@drawable/img_player_bacakground"
                    android:gravity="center_vertical"
                    android:orientation="horizontal"
                    android:visibility="visible" >

                    <ImageButton
                        android:id="@+id/ibn_start_suspend"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="18dip"
                        android:background="@drawable/bnx_suspend" />

                    <ImageButton
                        android:id="@+id/ibn_previous"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="18dip"
                        android:background="@drawable/bnx_previous" />

                    <ImageButton
                        android:id="@+id/ibn_next"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="18dip"
                        android:background="@drawable/bnx_next" />

                    <TextView
                        android:id="@+id/tv_songname"
                        android:layout_width="160dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dip"
                        android:layout_marginRight="5dip"
                        android:background="@drawable/img_player_kuang"
                        android:ellipsize="marquee"
                        android:focusable="true"
                        android:focusableInTouchMode="true"
                        android:gravity="center"
                        android:marqueeRepeatLimit="marquee_forever"
                        android:scrollHorizontally="true"
                        android:singleLine="true"
                        android:textSize="16sp" />

                    <ImageButton
                        android:id="@+id/ibn_mode"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@drawable/bnx_cycle" />
                </LinearLayout>

                <ImageButton
                    android:id="@+id/hand"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_toRightOf="@id/content"
                    android:background="@drawable/img_arrow_left" />
            </RelativeLayout>

            <SeekBar
                android:id="@+id/pb"
                style="@style/SeekBar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_x="0dp"
                android:layout_y="-5dp" />
        </AbsoluteLayout>
    </LinearLayout>

</RelativeLayout>
复制代码

接下来是ObjectActivity

它继承于Activity添加这么一层是为了让希望拥有这个悬浮mini播放器的类获得而不需要有的类不需要继承此类

最后是自定义seekbar所使用的style

看一下效果图:

    

 

源码下载:悬浮mini音乐播放器.zip

posted on   nuliniao  阅读(801)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2012年12月 >
25 26 27 28 29 30 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示