6.侧边栏菜单详情页
这是在viewpager里又加入了viewpager,先写viewpager,再写indicate
1. 菜单详情页基类
public abstract class BaseMenuDetailPager {
public Activity mActivity;
public View mRootView;// 根布局对象
public BaseMenuDetailPager(Activity activity) {
mActivity = activity;
mRootView = initViews();
}
/**
* 初始化界面
*/
public abstract View initViews();
/**
* 初始化数据
*/
public void initData() {
}
}
2.页签详情页
public class TabDetailPager extends BaseMenuDetailPager {
NewsTabData mTabData;
private TextView tvText;
public TabDetailPager(Activity activity, NewsTabData newsTabData) {
super(activity);
mTabData = newsTabData;
}
@Override
public View initViews() {
tvText = new TextView(mActivity);
tvText.setText("页签详情页");
tvText.setTextColor(Color.RED);
tvText.setTextSize(25);
tvText.setGravity(Gravity.CENTER);
return tvText;
}
@Override
public void initData() {
tvText.setText(mTabData.title);
}
}
3. 菜单详情页-新闻
news_menu_detail,不过写到这里时里面只有一个viewpager
<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="wrap_content"
android:orientation="horizontal" >
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent"
android:padding="5dp"
android:src="@drawable/news_cate_arr" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp_menu_detail"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
public class NewsMenuDetailPager extends BaseMenuDetailPager {
private ViewPager mViewPager;
private ArrayList<TabDetailPager> mPagerList;//11个页签
private ArrayList<NewsTabData> mNewsTabData;// 11个页签的网络数据,在NewsData里定义了
public NewsMenuDetailPager(Activity activity,//这样写就把解析的11个页面传过来了
ArrayList<NewsTabData> children) {
super(activity);
mNewsTabData = children;
}
@Override
public View initViews() {
View view = View.inflate(mActivity, R.layout.news_menu_detail, null);
mViewPager = (ViewPager) view.findViewById(R.id.vp_menu_detail);
return view;
}
@Override
public void initData() {
mPagerList = new ArrayList<TabDetailPager>();
// 初始化页签数据
for (int i = 0; i < mNewsTabData.size(); i++) {
TabDetailPager pager = new TabDetailPager(mActivity, mNewsTabData.get(i));
mPagerList.add(pager);
}
mViewPager.setAdapter(new MenuDetailAdapter());
}
class MenuDetailAdapter extends PagerAdapter {
@Override
public int getCount() {
return mPagerList.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
TabDetailPager pager = mPagerList.get(position);
container.addView(pager.mRootView);
pager.initData();
return pager.mRootView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
}
4.其他页面,只是暂时这样写
/**
* 菜单详情页-互动
*
* @author Kevin
*
*/
public class InteractMenuDetailPager extends BaseMenuDetailPager {
public InteractMenuDetailPager(Activity activity) {
super(activity);
}
@Override
public View initViews() {
TextView text = new TextView(mActivity);
text.setText("菜单详情页-互动");
text.setTextColor(Color.RED);
text.setTextSize(25);
text.setGravity(Gravity.CENTER);
return text;
}
}