引导页,代码很简单,用个viewpager就搞定了,这里给出一个延时跳转的代码。我是通过pos判断当前是第几张图片,然后进行延时跳转。
文章图片
MainTabActivity(主界面): package com.apk.bilibili.activity
;
import android.os.Bundle
;
import android.support.v4.app.Fragment
;
import android.support.v4.app.FragmentActivity
;
import android.support.v4.app.FragmentManager
;
import android.support.v4.app.FragmentTransaction
;
import android.view.View
;
import android.view.Window
;
import android.widget.ImageButton
;
import android.widget.LinearLayout
;
import com.apk.bilibili.R
;
import com.apk.bilibili.fragment.HomeFragment
;
import com.apk.bilibili.fragment.MineFragment
;
import com.apk.bilibili.fragment.NoticeFragment
;
import butterknife.ButterKnife
;
import
butterknife.InjectView
;
public class MainTabActivity
extends FragmentActivity
implements View.OnClickListener{
@InjectView(R.id.
tab_home) LinearLayout
mTabHome
;
@InjectView(R.id.
tab_mine) LinearLayout
mTabMine
;
@InjectView(R.id.
tab_notice) LinearLayout
mTabNotice
;
@InjectView(R.id.
tab_home_img) ImageButton
mImgHome
;
@InjectView(R.id.
tab_notice_img) ImageButton
mImgNotice
;
@InjectView(R.id.
tab_mine_img) ImageButton
mImgMine
;
private Fragment
mHome
;
private Fragment
mNotice
;
private Fragment
mMine
;
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
;
requestWindowFeature(Window.
FEATURE_NO_TITLE)
;
setContentView(R.layout.
activity_main_tab)
;
ButterKnife.
inject(
this)
;
setSelect(
0)
;
initEvent()
;
}
private void
initEvent() {
mTabHome.setOnClickListener(
this)
;
mTabNotice.setOnClickListener(
this)
;
mTabMine.setOnClickListener(
this)
;
}
private void
setSelect(
int i)
{
FragmentManager fm = getSupportFragmentManager()
;
FragmentTransaction transaction = fm.beginTransaction()
;
hideFragment(transaction)
;
switch (i)
{
case
0:
if (
mHome ==
null)
{
mHome =
new HomeFragment()
;
transaction.add(R.id.
id_content
,
mHome)
;
}
else
{
transaction.show(
mHome)
;
}
mImgHome.setImageResource(R.drawable.
home_pressed)
;
break;
case
1:
if (
mNotice ==
null)
{
mNotice =
new NoticeFragment()
;
transaction.add(R.id.
id_content
,
mNotice)
;
}
else
{
transaction.show(
mNotice)
;
}
mImgNotice.setImageResource(R.drawable.
notice_pressed)
;
break;
case
2:
if (
mMine ==
null)
{
mMine =
new MineFragment()
;
transaction.add(R.id.
id_content
,
mMine)
;
}
else
{
transaction.show(
mMine)
;
}
mImgMine.setImageResource(R.drawable.
mine_pressed)
;
break;
default:
break;
}
transaction.commit()
;
}
private void
hideFragment(FragmentTransaction transaction)
{
if (
mHome !=
null)
{
transaction.hide(
mHome)
;
}
if (
mNotice !=
null)
{
transaction.hide(
mNotice)
;
}
if (
mMine !=
null)
{
transaction.hide(
mMine)
;
}
}
@Override
public void
onClick(View v)
{
resetImgs()
;
switch (v.getId())
{
case R.id.
tab_home:
setSelect(
0)
;
break;
case R.id.
tab_notice:
setSelect(
1)
;
break;
case R.id.
tab_mine:
setSelect(
2)
;
break;
default:
break;
}
}
/**
* 切换图片至暗色
*/
private void
resetImgs() {
mImgHome.setImageResource(R.drawable.
home_normal)
;
mImgNotice.setImageResource(R.drawable.
notice_normal)
;
mImgMine.setImageResource(R.drawable.
mine_normal)
;
}
} 布局文件:
文章图片
tab_button:
xml version=
"1.0"
encoding=
"utf-8"
?>
android
:layout_height=
"65dp"
android
:orientation=
"horizontal"
android
:background=
"#FFFFFF"
>
android
:layout_width=
"0dp"
android
:layout_height=
"fill_parent"
android
:layout_weight=
"1"
android
:gravity=
"center"
android
:orientation=
"vertical"
>
android
:id=
"@+id/tab_home_img"
android
:layout_width=
"fill_parent"
android
:layout_height=
"fill_parent"
android
:clickable=
"false"
android
:src=
"https://www.it610.com/article/@drawable/home_pressed"
/>
android
:layout_width=
"0dp"
android
:layout_height=
"fill_parent"
android
:layout_weight=
"1"
android
:gravity=
"center"
android
:orientation=
"vertical"
>
android
:id=
"@+id/tab_notice_img"
android
:layout_width=
"fill_parent"
android
:layout_height=
"fill_parent"
android
:clickable=
"false"
android
:src=
"https://www.it610.com/article/@drawable/notice_normal"
/>
android
:layout_width=
"0dp"
android
:layout_height=
"fill_parent"
android
:layout_weight=
"1"
android
:gravity=
"center"
android
:orientation=
"vertical"
>
android
:id=
"@+id/tab_mine_img"
android
:layout_width=
"fill_parent"
android
:layout_height=
"fill_parent"
android
:clickable=
"false"
android
:src=
"https://www.it610.com/article/@drawable/mine_normal"
/>
Fragment: 1、HomeFragment: package com.apk.bilibili.fragment
;
import android.os.Bundle
;
import android.support.v4.app.Fragment
;
import android.support.v4.view.ViewPager
;
import android.view.LayoutInflater
;
import android.view.View
;
import android.view.ViewGroup
;
import com.apk.bilibili.R
;
import com.apk.bilibili.utils.TabAdapter
;
import com.viewpagerindicator.TabPageIndicator
;
import java.util.ArrayList
;
import java.util.List
;
public class HomeFragment
extends Fragment {
private ViewPager
mViewPager
;
private TabPageIndicator
mTabPageIndicator
;
private TabAdapter
mAdapter
;
private List
@Override
public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.
home
, container
, false)
;
mViewPager=(ViewPager) view.findViewById(R.id.
id_viewpager)
;
mTabPageIndicator = (TabPageIndicator) view.findViewById(R.id.
id_indicator)
;
mAdapter =
new TabAdapter(getFragmentManager())
;
mViewPager.setAdapter(
mAdapter)
;
mTabPageIndicator.setViewPager(
mViewPager
,
0)
;
Recommend_Fragment first_tab =
new Recommend_Fragment()
;
Animation_Fragment second_tab =
new Animation_Fragment()
;
mFragments.add(first_tab)
;
mFragments.add(second_tab)
;
return view
;
}
}
NoticeFragment: package com.apk.bilibili.fragment
;
import android.content.Intent
;
import android.os.Bundle
;
import android.support.v4.app.Fragment
;
import android.view.LayoutInflater
;
import android.view.View
;
import android.view.ViewGroup
;
import android.widget.Button
;
import com.apk.bilibili.R
;
import com.apk.bilibili.activity.SignIn
;
public class
NoticeFragment
extends Fragment {
private Button
mNotice_sign_in
;
@Override
public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.
notice
, container
, false)
;
mNotice_sign_in=(Button) view.findViewById(R.id.
notice_sign_in)
;
mNotice_sign_in.setOnClickListener(
new View.OnClickListener() {
@Override
public void
onClick(View view) {
Intent intent =
new Intent(getActivity()
,SignIn.
class)
;
startActivity(intent)
;
}
})
;
return view
;
}
}
MineFragment: package com.apk.bilibili.fragment
;
import android.content.Intent
;
import android.os.Bundle
;
import android.support.v4.app.Fragment
;
import android.view.LayoutInflater
;
import android.view.View
;
import android.view.ViewGroup
;
import android.widget.ImageButton
;
import com.apk.bilibili.R
;
import com.apk.bilibili.activity.MineFourthImageButton
;
import com.apk.bilibili.activity.MineImageButton
;
import com.apk.bilibili.activity.MineSecondImageButton
;
import com.apk.bilibili.activity.MineThridImageButton
;
public class MineFragment
extends Fragment {
private ImageButton
mfourth_imageButton
;
private ImageButton
mthrid_imageButton
;
private ImageButton
mimageButton
;
private ImageButton
msecond_imageButton
;
@Override
public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.
mine
, container
, false)
;
mfourth_imageButton=(ImageButton) view.findViewById(R.id.
fourth_imageButton)
;
mfourth_imageButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void
onClick(View view) {
Intent intent =
new Intent(getActivity()
,MineFourthImageButton.
class)
;
startActivity(intent)
;
}
})
;
mthrid_imageButton=(ImageButton)view.findViewById(R.id.
thrid_imageButton)
;
mthrid_imageButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void
onClick(View view) {
Intent intent =
new Intent(getActivity()
,MineThridImageButton.
class)
;
startActivity(intent)
;
}
})
;
mimageButton=(ImageButton)view.findViewById(R.id.
imageButton)
;
mimageButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void
onClick(View view) {
Intent intent =
new Intent(getActivity()
,MineImageButton.
class)
;
startActivity(intent)
;
}
})
;
msecond_imageButton=(ImageButton)view.findViewById(R.id.
second_imageButton)
;
msecond_imageButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void
onClick(View view) {
Intent intent =
new Intent(getActivity()
,MineSecondImageButton.
class)
;
startActivity(intent)
;
}
})
;
return view
;
}
} Recommend_Fragment: package com.apk.bilibili.fragment
;
import android.app.Activity
;
import android.content.Context
;
import android.content.Intent
;
import android.os.Bundle
;
import android.support.v4.app.Fragment
;
import android.view.LayoutInflater
;
import android.view.View
;
import android.view.ViewGroup
;
import android.widget.AdapterView
;
import android.widget.GridView
;
import android.widget.SimpleAdapter
;
import com.apk.bilibili.R
;
import com.apk.bilibili.activity.Show
;
import com.apk.bilibili.utils.History
;
import java.util.ArrayList
;
import java.util.HashMap
;
import java.util.Map
;
import cn.bmob.v3.Bmob
;
import cn.bmob.v3.listener.SaveListener
;
/**
* Created by Administrator on 2016/6/5.
*/
public class Recommend_Fragment
extends Fragment {
protected Context
mContext
;
protected static ArrayList