一、启动页
二、主要页面
2、实现本地页面
3、实现网络页面
4、实现推荐页面
5、自定义播放器
一、启动页
展示启动页,3秒后跳转至主页面,实现点击马上跳转到主页面。
1、创建一个名为My_player的项目
API 19:Android4.4
创建一个名为Start_Activity 的窗体
把PNG图片login_icon复制到drawable里面
编写activi_start的布局
<?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" android:gravity="center"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/login_icon"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <ProgressBar android:layout_width="20dp" android:layout_height="20dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="正在加载"/> </LinearLayout> </LinearLayout>
在Start_Activity创建一个名为StartToMain()的方法
在方法里面实例化Itent 并实现窗口跳转
在onCreate里面实例化Handler,通过handler.postDelayed,设置延迟3S调用StartToMain
优化:
重写onDestroy()方法
调用handler.removeCallbacks;在页面销毁时停止线程。释放资源
重写onTouchEvent()方法
调用StartToMain();实现点击页面马上跳转
package com.example.administrator.my_player; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.MotionEvent; public class Start_Activity extends AppCompatActivity { private Handler handler; private boolean isFistStart=false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start_); handler=new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { StartToMain(); } },3000); } private void StartToMain(){ if(!isFistStart){ isFistStart=true; Intent intent=new Intent(Start_Activity.this,MainActivity.class); startActivity(intent); finish(); } } @Override public boolean onTouchEvent(MotionEvent event) { StartToMain(); return super.onTouchEvent(event); } @Override protected void onDestroy() { super.onDestroy(); } }
修改AndroidManifest.xml清单文件,首先进入Start_Activity
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.administrator.my_player"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> </activity> <activity android:name=".Start_Activity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
二、主要页面
创建顶部和底部的布局文件分别命名为titlebar.xml和bottombar.xml
titlebar.xml
<?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:background="#ff3097fd" android:orientation="horizontal" android:gravity="center_vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:src="@drawable/ic_topbanner_logo" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/tv_search" android:background="@drawable/tv_search_bg_selector" android:drawableLeft="@drawable/tv_search_drawable_selector" android:textColor="@drawable/tv_search_textcolor_selector" android:layout_marginLeft="8dp" android:clickable="true" android:text="全网搜索" android:textSize="18sp" android:drawablePadding="3dp"/> <RelativeLayout android:id="@+id/rl_game" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" > <TextView android:id="@+id/tv_game" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_topbanner_game"/> <ImageView android:layout_width="6dp" android:layout_height="6dp" android:layout_alignRight="@id/tv_game" android:background="@drawable/dot"/> </RelativeLayout> <ImageView android:id="@+id/iv_record" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_topbanner_record" android:layout_marginLeft="5dp" android:layout_marginRight="8dp" /> </LinearLayout>
bottombar.xml
<?xml version="1.0" encoding="utf-8"?> <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myRg" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="0dp" android:layout_weight="1" android:background="#dadad8" > <RadioButton android:id="@+id/radioButtonTJ" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:drawableTop="@drawable/rb_search_bg_drawable_recommend" style="@style/buttom_tag_styles" android:text="推荐页" /> <RadioButton android:id="@+id/radioButtonBD" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:drawableTop="@drawable/rb_search_bg_drawable_local" style="@style/buttom_tag_styles" android:text="本地页" /> <RadioButton android:id="@+id/radioButtonWL" style="@style/buttom_tag_styles" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:drawableTop="@drawable/rb_search_bg_drawable_network" android:text="网络页" /> </RadioGroup> \
其中有个
style="@style/buttom_tag_styles"
要在styles.xlm
<style name="buttom_tag_styles"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:gravity">center</item> <item name="android:button">@null</item> <item name="android:textColor">@drawable/text_coloce</item> <item name="android:layout_weight">1</item> </style>
编写activity_main.xml的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <include layout="@layout/titlebar" android:layout_height="0dp" android:layout_weight="1" android:layout_width="match_parent"></include> <FrameLayout android:id="@+id/fl_welcome_content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="8" > </FrameLayout> <include layout="@layout/bootmmt" android:layout_height="0dp" android:layout_weight="1" android:layout_width="match_parent"></include> </LinearLayout>
创建一个BasePager的抽象类
package com.example.administrator.my_player.Base; import android.content.Context; import android.view.View; public abstract class BasePager { public Context context; public View rootView; public boolean isInt=false; public BasePager(Context context) { this.context = context; rootView=initView(); } protected abstract View initView(); public void initData(){} }
创建一个BasePager的抽象类
package com.example.administrator.my_player.Base;
import android.content.Context;
import android.view.View;
public abstractclass BasePager {
public Context context;
public View rootView;
public boolean isInt=false;
public BasePager(Contextcontext) {
this.context = context;
rootView=initView();
}
protected abstract ViewinitView();
public void initData(){}
}
创建三个继承BasePager的类
创建三个对应的布局
现在先对Local进行,创建布局文件activity_local_page
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:divider="@null"
android:layout_width="match_parent"
android:layout_height="match_parent"/>