初学Android初级,第一篇博客文章,如有错误,还望批评指正!
本文主要内容以网易云音乐歌曲列表界面效果代码,播放音乐界面效果代码为主,并将ListView和ViewPager作为实现界面滑动功能的适配器控件进行穿插讲解。
读完本文你将了解到:
- 如何创建布局文件(线性布局及相对布局搭配使用)
- 如何使用ListView和ViewPager进行界面滑动和切换(Fragment)
- 利用缓存原理给布局视图控件赋值
- 如何将手机本地音乐导入到已编写运行好的程序中(多媒体Media)
Part1 效果图
最终效果图
Part2 整体思路详解
1.创建实体类
- 在Java中分别创建三个包
- fragment
- adapter(适配器)
- entity(实体类)
- 在实体类中创建java文件用于实体类(注意类名首字母大写)
- 定义需要的参数(title,album,artist,“Bitmap” albumBmp)
若定义类型为private型则需要进行set,get方法的构建
2. 创建layout文件
用于歌曲列表样式布局**,代码如下:
<Linear Layout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//运用相对布局文件
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">
//创建列表歌曲间的横线
<View
android:id="@+id/list_column_v"
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:visibility="visible"
></View>
//设置专辑图片样式
<ImageView
android:id="@+id/simple_cover_Iv"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBottom="@+id/linearLayout"
android:layout_marginStart="11dp"
android:layout_toEndOf="@+id/list_column_v"
android:src="@mipmap/default_cover" />
//运行线性布局文件进行TextView布局
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/simple_cover_Iv"
android:orientation="vertical"
android:layout_marginTop="5dp"