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
mFragments =
new ArrayList()
;
@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
Animation_Fragment:
package com.apk.bilibili.fragment
;
import android.app.Activity
;
import android.content.Context
;
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.ListView
;
import android.widget.SimpleAdapter
;
import com.apk.bilibili.R
;
import java.util.ArrayList
;
import java.util.HashMap
;
import java.util.Map
;
public class Animation_Fragment
extends Fragment {
protected Context
mContext
;
protected static ArrayList, Object>>
mListItems
;
static {
mListItems =
new ArrayList, Object>>()
;
Map, Object> map =
new HashMap, Object>()
;
map.put(
"title"
,
"Re:从零开始的异世界生活")
;
map.put(
"content"
,
"诅咒上身,倒数重开。绿林孤影犄角下,是失去理智的温柔...")
;
map.put(
"img"
,R.drawable.
item_first)
;
Map, Object> second_map =
new HashMap, Object>()
;
second_map.put(
"title"
,
"秒速五厘米")
;
second_map.put(
"content"
,
"[你知道樱花飘落的速度吗?]")
;
second_map.put(
"img"
,R.drawable.
item_second)
;
Map, Object> thrid_map =
new HashMap, Object>()
;
thrid_map.put(
"title"
,
"请问您今天要来点兔子吗??")
;
thrid_map.put(
"content"
,
"没有什么事是看一话点兔解决不了的...如果有,那就看两话!")
;
thrid_map.put(
"img"
,R.drawable.
item_thrid)
;
Map, Object> fourth_map =
new HashMap, Object>()
;
fourth_map.put(
"title"
,
"一周的朋友")
;
fourth_map.put(
"content"
,
"一周的友谊→重启→陌生...一次又一次。愿有朝一日,你也能记得这份感觉。")
;
fourth_map.put(
"img"
,R.drawable.
item_fourth)
;
Map, Object> fifth_map =
new HashMap, Object>()
;
fifth_map.put(
"title"
,
"线上游戏的老婆不可能是女生? 10")
;
fifth_map.put(
"content"
,
"学院祭来啦!我们要把胜利的旗帜插在那座城池上(╯`□′)╯")
;
fifth_map.put(
"img"
,R.drawable.
item_fifth)
;
Map, Object> sixth_map =
new HashMap, Object>()
;
sixth_map.put(
"title"
,
"花开伊吕波")
;
sixth_map.put(
"content"
,
"为改变、为了崭新的自己,离开诚实,旅馆工作开始!少女们怀揣梦想,在同一屋檐下成长,绽放!")
;
sixth_map.put(
"img"
,R.drawable.
item_sixth)
;
Map, Object> seventh_map =
new HashMap, Object>()
;
seventh_map.put(
"title"
,
"四月是你的谎言")
;
seventh_map.put(
"content"
,
"又到四月,从一个美丽的谎言开始。")
;
seventh_map.put(
"img"
,R.drawable.
item_seventh)
;
Map, Object> eighth_map =
new HashMap, Object>()
;
eighth_map.put(
"title"
,
"罪恶王冠")
;
eighth_map.put(
"content"
,
"[人为何互相伤害 彼此争斗呢]承受宿命之重 冠以王者之名")
;
eighth_map.put(
"img"
,R.drawable.
item_eighth)
;
Map, Object> ninth_map =
new HashMap, Object>()
;
ninth_map.put(
"title"
,
"我们大家的河合庄")
;
ninth_map.put(
"content"
,
"本宿舍自带三餐,自带奇葩舍友_(:з」∠)_还自带暗恋对象")
;
ninth_map.put(
"img"
,R.drawable.
item_ninth)
;
mListItems.add(map)
;
mListItems.add(second_map)
;
mListItems.add(thrid_map)
;
mListItems.add(fourth_map)
;
mListItems.add(fifth_map)
;
mListItems.add(sixth_map)
;
mListItems.add(seventh_map)
;
mListItems.add(eighth_map)
;
mListItems.add(ninth_map)
;
}
public static Animation_Fragment
newInstance(){
Animation_Fragment fragment=
new Animation_Fragment()
;
return fragment
;
}
public void
onAttach(Activity activity) {
super.onAttach(activity)
;
mContext = activity.getApplicationContext()
;
}
@Override
public View
onCreateView(LayoutInflater inflater
, ViewGroup container
, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.
animation
, null)
;
ListView mListView=(ListView) view.findViewById(R.id.
animation_ListView)
;
SimpleAdapter adapter =
new SimpleAdapter(
mContext
,
mListItems
,R.layout.
animation_item
,
new String[] {
"title"
,
"content"
,
"img"}
,
new int[] {R.id.
title_animation
, R.id.
content_animation
,R.id.
img_animation})
;
mListView.setAdapter(adapter)
;
return view
;
}
}
TabAdapter:
package com.apk.bilibili.utils
;
import android.support.v4.app.Fragment
;
import android.support.v4.app.FragmentManager
;
import android.support.v4.app.FragmentPagerAdapter
;
import com.apk.bilibili.fragment.Recommend_Fragment
;
import com.apk.bilibili.fragment.Animation_Fragment
;
public class TabAdapter
extends FragmentPagerAdapter
{
public static String[]
TITLES =
new String[]
{
"推荐"
,
"动画"}
;
public TabAdapter(FragmentManager fm)
{
super(fm)
;
}
@Override
public Fragment
getItem(
int position)
{
switch (position) {
case
0:
return Recommend_Fragment.
newInstance()
;
case
1:
return Animation_Fragment.
newInstance()
;
}
return null;
}
@Override
public int
getCount()
{
return
TITLES.
length
;
}
@Override
public CharSequence
getPageTitle(
int position)
{
return
TITLES[position]
;
}
}
界面的代码就只有这些(还有 bmob初始化用的
Application ID你们需要改一下这里用的是我的)
至于那些图片的资源文件,都是些我自己剪的,还有一些样式。有需要的,或者需要源代码的可以找我要。这里只是展示一下大致的效果,viewpager和fragment怎么使用,如何使用viewpagerindicator。
这里向大家推荐一下bmob,比如账户,系统消息,历史记录都有用到bmob。
下一篇将是这个demo的一些功能实现