zoukankan      html  css  js  c++  java
  • 婧婧音乐开发笔记01篇-项目组织结构和布局文件

    学习Android已经一段时间了打算做一款播放器来练练手。下面的效果图是开发婧婧音乐第一阶段的效果图:

    一:1.0阶段可以满足基本的功能:

        1.自动获取SD卡的音乐文件,并以ListView的形式进行了显示   

        2.单击ListView的Item能够播放音乐     

       3.可以实现后台音乐播放     

       4.暂停,播放,上一曲,下一曲的播放

    二.  在项目中用到了以下知识点:
      1.ListView的优化,BaseAdapter的优化
      2.UI的布局与设计
      3.SD卡的音乐读取
      4.Cursor的遍历,注意Cursor默认是下标-1开始的
      5.contentProvider的使用
      6.Service的使用
      7.Service与Activity的通信
      8.项目组织结构的使用:建立项目时一开始就建立了若干个项目可能需要的包把框架搭建好。

    三.项目的组织结构:

    以上分别对应的是:活动包,适配器包,实体包,服务包,和工具包

    因为需要后台播放所以创建一个MusicPlayerService的类来提供相关的播放方法,并在主活动中调用。

    DataHelper封装了变量SD卡音乐的静态方法。

    四.项目的布局结构

      

      activity_welcome:是一张欢迎界面的布局,点击应用就像微信一样先有一张引导界面

      bottom代表:主布局下面的布局,这样做可以提高布局 的复用率。

      top与bottom相同

      item代表ListView的布局

      musicplayer_activity:播放界面主布局。

    五.代码  

      先把布局的代码放上来,因为一般设计先从视图开始的。

      

    1.res/layout/ welcome_activity:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.LZT.mp3player.WelcomeActivity"
        android:background="@drawable/guide" >
    
        <TextView
            
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#f8f"
            android:textSize="20dp"
            android:text="@string/welcome_to_music" />
    
    </RelativeLayout>


    2.res/layout/musicplayer_activity的布局:包含一个头布局一个尾布局和一个listview

    <?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="match_parent"
       
        android:orientation="vertical" >
        
        <include layout="@layout/top_layout"/>
          <ListView
              android:id="@+id/mp3_lv"
              android:padding="5dp"
             
              android:dividerHeight="2dp"
              android:layout_weight="1"
              android:layout_width="match_parent"
              android:layout_height="0dp">
              </ListView>
         <include layout="@layout/bottom_layout"/>
    </LinearLayout>


    3.top_layout和bottom_layout:

      

    <?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="50dp"
        android:background="#20b2aa"
        android:orientation="vertical" >
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <ImageButton
        android:id="@+id/play_mode"
        android:layout_marginLeft="5dp"
        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/mode_a"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="本地音乐"
        android:textSize="20dp"
        android:layout_centerInParent="true"
        android:textColor="#fff"
        android:id="@+id/title_top"/>
    <ImageButton
        android:id="@+id/love_bt"
         android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/love"/>
    </RelativeLayout>
    </LinearLayout>
    <?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="40dp"
        android:background="#20b2aa"
        android:orientation="horizontal" >
    
        <ImageButton
            android:id="@+id/music_logo"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_marginTop="5dp"
            android:background="#20b2aa"
            android:src="@drawable/music" />
        <ImageButton
            android:id="@+id/pre_bt"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            
            android:background="@drawable/pre_button_pressed" />
            <ImageButton
            android:id="@+id/play_pause_bt"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/play_button_pressed"/>
                <ImageButton
            android:id="@+id/next_bt"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/next_button_pressed" />
     
    </LinearLayout>
    <?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="match_parent"
        android:orientation="vertical" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/album_img"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:src="@drawable/default_album"/>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="我是歌手"
                    android:id="@+id/title_tv"/>
                  <TextView
                     
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="你是傻逼"
                    android:id="@+id/artist_tv"/>
                </LinearLayout>
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
            <TextView
                
                android:id="@+id/duration"
                android:layout_marginRight="10dp"
                android:layout_marginTop="20dp"
                 android:layout_alignParentRight="true"
                android:text="4:00"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            </RelativeLayout>
            </LinearLayout>
    
    </LinearLayout>

    以上是项目的组织工程和布局文件,下篇文章开始介绍业务逻辑。

  • 相关阅读:
    ie6-ie8中不支持opacity透明度的解决方法
    html5游戏-包围盒检测算法
    流媒体 8——因特网 tcp/ip
    流媒体 7——多媒体网络应用与交换
    流媒体 6——MPEG电视
    流媒体 5——MPEG声音
    流媒体 4——数字电视基础
    流媒体 3——彩色数字图像基础
    流媒体 2——数据无损压缩
    流媒体 1——概述+声音数字编码(pcm,dm......)
  • 原文地址:https://www.cnblogs.com/taotaomajia/p/4617721.html
Copyright © 2011-2022 走看看