Как реализовать воспроизведение музыки с помощью настраиваемой панели уведомлений на экране
Я работаю над музыкальным приложением и хочу, чтобы на главном экране отображалось уведомление о воспроизведении музыки xyz (всплывающая панель уведомлений, например, spotify).
Как я могу показать такую всплывающую панель уведомлений в конце плейлиста? когда играет музыка, и когда пользователь нажимает на эту панель, он будет перенаправлен на экран воспроизведения музыки.
Когда музыка не воспроизводится, эта панель автоматически скрывается, а также требуется анимировать эту панель во время скрытия и как я могу отобразить ее поверх списка внизу
в качестве примера, пожалуйста, посмотрите ниже
1 ответ
Используйте силу RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/playlist"
android:layout_above="@+id/notification"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="@+id/notification"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView
android:id="@+id/imgview_album_art"
android:src="image"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_width="48dp"
android:layout_height="48dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btn_play_pause"
android:layout_toRightOf="@+id/imgview_album_art">
<TextView
android:text="Paradise"
android:id="@+id/textview_song_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Coldplay - Mylo Xyloto"
android:id="@+id/textview_artist_album"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ImageButton
android:id="@+id/btn_play_pause"
android:padding="8dp"
android:background="@android:color/transparent"
android:src="@android:drawable/ic_media_pause"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>