【发布时间】:2016-01-04 20:16:17
【问题描述】:
我正在创建一个音乐播放器应用,以下是活动列表:
- WelcomeActivity
- SongsListActivity
- 音乐播放活动
- SongsListActivity 将显示可用歌曲列表,点击项目后,您将转到 MusicPlayActivity,这将触发 SongService,进而在后台播放歌曲。
下面是MusicPlayActivity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/background">
<include layout="@layout/musicpanel"></include>
</RelativeLayout>
以下代码适用于 MusicPlayActivity 中包含的音乐面板
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:id="@+id/playPause"
android:layout_gravity="bottom"
android:layout_marginLeft="51dp"
android:layout_marginStart="51dp"
android:layout_alignTop="@+id/stop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:id="@+id/stop"
android:layout_gravity="bottom"
android:layout_marginBottom="28dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/playPause"
android:layout_toEndOf="@+id/playPause"
android:layout_marginLeft="67dp"
android:layout_marginStart="67dp" />
</RelativeLayout>
如果用户从 MusicPlayActivity 中点击返回按钮,我们需要显示 SongListActivity 所以这里我想显示音乐面板。
我的问题是创建音乐面板的最佳做法是什么?
现在我将它包含在 xml 中,但在每个活动中,我每次都需要为音乐面板的所有组件(如播放、暂停、下一个、上一个)设置侦听器
提前致谢
【问题讨论】:
-
您想说音乐面板应该在 SongListActivty 和 MusicPlayActivty 中都可用?
标签: android android-layout audio-player android-music-player