自定义mini悬浮播放器【原创】

本文分享了一款自定义Mini悬浮播放器的设计与实现过程,重点介绍了player.xml布局文件和ObjectActivity类,通过绝对布局实现了特定尺寸播放器的精确控制,并提供了一个自定义SeekBar样式。

 

本帖最后由 艾迦号 于 2012-12-19 11:23 编辑

资源下载链接:

自定义mini悬浮播放器【原创】
http://www.apkbus.com/forum.php?mod=viewthread&tid=85890&fromuid=50124


第一次总结,有什么问题请多多包涵
先看效果
         

在这个工程中最为重要的就是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播放器的类获得而不需要有的类不需要继承此类

<ignore_js_op>1.png 


<ignore_js_op>2.png 

<ignore_js_op>3.png 

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

<ignore_js_op>4.png 



第一次发帖,有些紧张,没有什么经验,要是说得不好不清楚请多多包涵,有什么问题尽管提,要是能解决我都尽力解决的

转载于:https://www.cnblogs.com/ajh-naruto-zhh/archive/2012/12/19/2824644.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值