Android實(shí)現(xiàn)網(wǎng)易云音樂高仿版流程
效果圖
效果圖依次為發(fā)現(xiàn)界面頂部,包含首頁輪播圖,水平滾動(dòng)的按鈕,推薦歌單;然后是發(fā)現(xiàn)界面推薦單曲,點(diǎn)擊單曲就是直接進(jìn)入播放界面;最后是全局播放控制條上點(diǎn)擊播放列表按鈕顯示的播放列表彈窗。
整體分析
整體使用RecycerView實(shí)現(xiàn),每個(gè)不同的塊是一個(gè)Item,例如:輪播圖是一個(gè)Item,按鈕也是,推薦歌單和下面的歌單是,推薦單曲,還有最后的自定義首頁那塊也是一樣。
提示:之所以把推薦歌單下面的歌單和推薦歌單標(biāo)題放一個(gè)Item,主要是首頁要實(shí)現(xiàn)自定義順序功能,更方便管理。
輪播圖
布局
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_height="wrap_content" android:layout_margin="@dimen/padding_outer"> <com.youth.banner.Banner android:id="@+id/banner" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintDimensionRatio="H,0.389" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
顯示數(shù)據(jù)
//banner BannerData data = (BannerData) d; Banner bannerView = holder.getView(R.id.banner); BannerImageAdapter<Ad> bannerImageAdapter = new BannerImageAdapter<Ad>(data.getData()) { @Override public void onBindView(BannerImageHolder holder, Ad data, int position, int size) { ImageUtil.show(getContext(), (ImageView) holder.itemView, data.getIcon()); } }; bannerView.setAdapter(bannerImageAdapter); bannerView.setOnBannerListener(onBannerListener); bannerView.setBannerRound(DensityUtil.dip2px(getContext(), 10)); //添加生命周期觀察者 bannerView.addBannerLifecycleObserver(fragment); bannerView.setIndicator(new CircleIndicator(getContext()));
按鈕
布局
<?xml version="1.0" encoding="utf-8"?> <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingVertical="@dimen/padding_outer" android:scrollbars="none"> <LinearLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingHorizontal="@dimen/padding_meddle"> </LinearLayout> </HorizontalScrollView>
顯示數(shù)據(jù)
LinearLayout container = holder.getView(R.id.container); if (container.getChildCount() > 0) { //已經(jīng)添加了 return; } //橫向顯示5個(gè)半 float containerWidth = ScreenUtil.getScreenWith(container.getContext()) - DensityUtil.dip2px(container.getContext(), 10 * 2); int itemWidth = (int) (containerWidth / 5.5); DiscoveryButtonBinding binding; LinearLayout.LayoutParams layoutParams; for (IconTitleButtonData it : data.getData()) { binding = DiscoveryButtonBinding.inflate(LayoutInflater.from(getContext())); binding.icon.setImageResource(it.getIcon()); binding.title.setText(it.getTitle()); if (it.getIcon() == R.drawable.day_recommend) { SuperViewUtil.show(binding.more); //顯示日期 binding.more.setText(String.valueOf(SuperDateUtil.currentDay())); } //設(shè)置點(diǎn)擊事件 binding.getRoot().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); layoutParams = new LinearLayout.LayoutParams(itemWidth, ViewGroup.LayoutParams.WRAP_CONTENT); container.addView(binding.getRoot(), layoutParams); }
推薦歌單
布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <include layout="@layout/item_discovery_title" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingHorizontal="@dimen/padding_outer" android:paddingBottom="@dimen/d5" /> </LinearLayout>
顯示數(shù)據(jù)
private void bindSheetData(BaseViewHolder holder, SheetData data) { //設(shè)置標(biāo)題,將標(biāo)題放到每個(gè)具體的item上,好處是方便整體排序 holder.setText(R.id.title, R.string.recommend_sheet); //顯示更多容器 holder.setVisible(R.id.more, true); holder.getView(R.id.more).setOnClickListener(v -> { }); RecyclerView listView = holder.getView(R.id.list); if (listView.getAdapter() == null) { //設(shè)置顯示3列 GridLayoutManager layoutManager = new GridLayoutManager(listView.getContext(), 3); listView.setLayoutManager(layoutManager); sheetAdapter = new SheetAdapter(R.layout.item_sheet); //item點(diǎn)擊 sheetAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) { if (discoveryAdapterListener != null) { discoveryAdapterListener.onSheetClick((Sheet) adapter.getItem(position)); } } }); listView.setAdapter(sheetAdapter); GridDividerItemDecoration itemDecoration = new GridDividerItemDecoration(getContext(), (int) DensityUtil.dip2px(getContext(), 5F)); listView.addItemDecoration(itemDecoration); } sheetAdapter.setNewInstance(data.getData()); }
底部
布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginVertical="@dimen/padding_outer" android:gravity="center_horizontal" android:orientation="vertical"> <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical"> <TextView android:id="@+id/refresh_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/refresh" android:gravity="center_vertical" android:text="@string/click_refresh" android:textColor="@color/link" android:textSize="@dimen/text_small" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/padding_small" android:text="@string/change_content" android:textColor="@color/black80" android:textSize="@dimen/text_small" /> </androidx.appcompat.widget.LinearLayoutCompat> <com.google.android.material.button.MaterialButton android:id="@+id/custom" style="@style/Widget.MaterialComponents.Button.UnelevatedButton" android:layout_width="wrap_content" android:layout_height="@dimen/d30" android:layout_marginTop="@dimen/padding_outer" android:backgroundTint="?attr/colorSurface" android:insetTop="0dp" android:insetBottom="0dp" android:text="@string/custom_discovery" android:textColor="@color/black80" android:textSize="@dimen/text_small" app:cornerRadius="@dimen/d15" app:elevation="0dp" app:strokeColor="@color/black80" app:strokeWidth="@dimen/d0_5" /> </LinearLayout>
顯示數(shù)據(jù)
holder.getView(R.id.refresh_button).setOnClickListener(v -> discoveryAdapterListener.onRefreshClick()); holder.getView(R.id.custom).setOnClickListener(v -> discoveryAdapterListener.onCustomDiscoveryClick());
迷你控制條
他是一個(gè)自定義Fragment,哪里要顯示就放到哪里就行了。
播放列表彈窗
/** * 播放列表對話框 */ public class MusicPlayListDialogFragment extends BaseViewModelBottomSheetDialogFragment<FragmentDialogAudioPlayListBinding> { ... @Override protected void initListeners() { super.initListeners(); //刪除所有按鈕點(diǎn)擊 binding.deleteAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //關(guān)閉對話框 dismiss(); //刪除全部音樂 getMusicListManager().deleteAll(); } }); //item中子控件點(diǎn)擊 //刪除按鈕點(diǎn)擊 adapter.addChildClickViewIds(R.id.delete); adapter.setOnItemChildClickListener(new OnItemChildClickListener() { @Override public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { //由于這里只有一個(gè)按鈕點(diǎn)擊 //所以可以不判斷 if (R.id.delete == view.getId()) { //刪除按鈕點(diǎn)擊 removeItem(position); } } }); //循環(huán)模式點(diǎn)擊 binding.loopModel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //更改循環(huán)模式 getMusicListManager().changeLoopModel(); //顯示循環(huán)模式 showLoopModel(); } }); //設(shè)置item點(diǎn)擊事件 adapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { //關(guān)閉dialog //可以根據(jù)具體的業(yè)務(wù)邏輯來決定是否關(guān)閉 dismiss(); //播放點(diǎn)擊的這首音樂 getMusicListManager().play(getMusicListManager().getDatum().get(position)); } }); } private void removeItem(int position) { adapter.removeAt(position); //從列表管理器中刪除 getMusicListManager().delete(position); showCount(); } /** * 顯示循環(huán)模式 */ private void showLoopModel() { PlayListUtil.showLoopModel(getMusicListManager().getLoopModel(), binding.loopModel); } private void showCount() { binding.count.setText(String.format("(%d)", getMusicListManager().getDatum().size())); } }
到此這篇關(guān)于Android實(shí)現(xiàn)網(wǎng)易云音樂高仿版流程的文章就介紹到這了,更多相關(guān)Android網(wǎng)易云音樂內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Android項(xiàng)目實(shí)戰(zhàn)教程之高仿網(wǎng)易云音樂啟動(dòng)頁實(shí)例代碼
- Android實(shí)現(xiàn)網(wǎng)易云推薦歌單界面
- Android實(shí)現(xiàn)網(wǎng)易云音樂的旋轉(zhuǎn)專輯View
- Android5.0以上實(shí)現(xiàn)全透明的狀態(tài)欄方法(仿網(wǎng)易云界面)
- Android仿網(wǎng)易云音樂播放界面
- 漂亮的Android音樂歌詞控件 仿網(wǎng)易云音樂滑動(dòng)效果
- Android控件RecyclerView實(shí)現(xiàn)混排效果仿網(wǎng)易云音樂
相關(guān)文章
Android中判斷網(wǎng)絡(luò)是否可用的代碼分享
這篇文章主要介紹了Android中判斷網(wǎng)絡(luò)是否可用的代碼分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-03-03Android利用Badge組件實(shí)現(xiàn)未讀消息小紅點(diǎn)
在?App?的運(yùn)營中,活躍度是一個(gè)重要的指標(biāo),日活/月活……為了提高活躍度,就發(fā)明了小紅點(diǎn)。這一篇,來介紹一個(gè)徽標(biāo)(Badge)組件,能夠快速搞定應(yīng)用內(nèi)的小紅點(diǎn),希望對大家有所幫助2023-01-01Android 實(shí)現(xiàn)為點(diǎn)擊事件添加震動(dòng)效果
這篇文章主要介紹了Android 實(shí)現(xiàn)為點(diǎn)擊事件添加震動(dòng)效果,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03手勢滑動(dòng)結(jié)束Activity基本功能的實(shí)現(xiàn)(一)
這篇文章主要為大家詳細(xì)介紹了手勢滑動(dòng)結(jié)束Activity基本功能的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Android RecycleView使用(CheckBox全選、反選、單選)
這篇文章主要為大家詳細(xì)介紹了Android RecycleView使用,CheckBox全選、反選、單選效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09android獲取監(jiān)聽SD Card狀態(tài)的方法
這篇文章主要介紹了android獲取監(jiān)聽SD Card狀態(tài)的方法,涉及Android實(shí)現(xiàn)SD Card監(jiān)聽的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04Android 后臺(tái)生成長圖并分享示例(非長截圖)
這篇文章主要介紹了Android 后臺(tái)生成長圖并分享示例(非長截圖),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08關(guān)于Android中點(diǎn)擊通知欄的通知啟動(dòng)Activity問題解決
這篇文章主要介紹了關(guān)于解決Android中點(diǎn)擊通知欄的通知啟動(dòng)Activity問題的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-03-03