码迷,mamicode.com
首页 > 其他好文 > 详细

6.侧边栏菜单详情页

时间:2015-10-27 23:35:46      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:

这是在viewpager里又加入了viewpager,先写viewpager,再写indicate
技术分享
1. 菜单详情页基类
  1. public abstract class BaseMenuDetailPager {
  2. public Activity mActivity;
  3. public View mRootView;// 根布局对象
  4. public BaseMenuDetailPager(Activity activity) {
  5. mActivity = activity;
  6. mRootView = initViews();
  7. }
  8. /**
  9. * 初始化界面
  10. */
  11. public abstract View initViews();
  12. /**
  13. * 初始化数据
  14. */
  15. public void initData() {
  16. }
  17. }
2.页签详情页
  1. public class TabDetailPager extends BaseMenuDetailPager {
  2. NewsTabData mTabData;
  3. private TextView tvText;
  4. public TabDetailPager(Activity activity, NewsTabData newsTabData) {
  5. super(activity);
  6. mTabData = newsTabData;
  7. }
  8. @Override
  9. public View initViews() {
  10. tvText = new TextView(mActivity);
  11. tvText.setText("页签详情页");
  12. tvText.setTextColor(Color.RED);
  13. tvText.setTextSize(25);
  14. tvText.setGravity(Gravity.CENTER);
  15. return tvText;
  16. }
  17. @Override
  18. public void initData() {
  19. tvText.setText(mTabData.title);
  20. }
  21. }
3. 菜单详情页-新闻
news_menu_detail,不过写到这里时里面只有一个viewpager
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical" >
  5. <LinearLayout
  6. android:layout_width="match_parent"
  7. android:layout_height="wrap_content"
  8. android:orientation="horizontal" >
  9. <com.viewpagerindicator.TabPageIndicator
  10. android:id="@+id/indicator"
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content"
  13. android:layout_weight="1" />
  14. <ImageButton
  15. android:id="@+id/btn_next"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:layout_gravity="center_vertical"
  19. android:background="@android:color/transparent"
  20. android:padding="5dp"
  21. android:src="@drawable/news_cate_arr" />
  22. </LinearLayout>
  23. <android.support.v4.view.ViewPager
  24. android:id="@+id/vp_menu_detail"
  25. android:layout_width="match_parent"
  26. android:layout_height="match_parent" />
  27. </LinearLayout>

  1. public class NewsMenuDetailPager extends BaseMenuDetailPager {
  2. private ViewPager mViewPager;
  3. private ArrayList<TabDetailPager> mPagerList;//11个页签
  4. private ArrayList<NewsTabData> mNewsTabData;// 11个页签的网络数据,在NewsData里定义了
  5. public NewsMenuDetailPager(Activity activity,//这样写就把解析的11个页面传过来了
  6. ArrayList<NewsTabData> children) {
  7. super(activity);
  8. mNewsTabData = children;
  9. }
  10. @Override
  11. public View initViews() {
  12. View view = View.inflate(mActivity, R.layout.news_menu_detail, null);
  13. mViewPager = (ViewPager) view.findViewById(R.id.vp_menu_detail);
  14. return view;
  15. }
  16. @Override
  17. public void initData() {
  18. mPagerList = new ArrayList<TabDetailPager>();
  19. // 初始化页签数据
  20. for (int i = 0; i < mNewsTabData.size(); i++) {
  21. TabDetailPager pager = new TabDetailPager(mActivity, mNewsTabData.get(i));
  22. mPagerList.add(pager);
  23. }
  24. mViewPager.setAdapter(new MenuDetailAdapter());
  25. }
  26. class MenuDetailAdapter extends PagerAdapter {
  27. @Override
  28. public int getCount() {
  29. return mPagerList.size();
  30. }
  31. @Override
  32. public boolean isViewFromObject(View arg0, Object arg1) {
  33. return arg0 == arg1;
  34. }
  35. @Override
  36. public Object instantiateItem(ViewGroup container, int position) {
  37. TabDetailPager pager = mPagerList.get(position);
  38. container.addView(pager.mRootView);
  39. pager.initData();
  40. return pager.mRootView;
  41. }
  42. @Override
  43. public void destroyItem(ViewGroup container, int position, Object object) {
  44. container.removeView((View) object);
  45. }
  46. }
  47. }
4.其他页面,只是暂时这样写

  1. /**
  2. * 菜单详情页-互动
  3. *
  4. * @author Kevin
  5. *
  6. */
  7. public class InteractMenuDetailPager extends BaseMenuDetailPager {
  8. public InteractMenuDetailPager(Activity activity) {
  9. super(activity);
  10. }
  11. @Override
  12. public View initViews() {
  13. TextView text = new TextView(mActivity);
  14. text.setText("菜单详情页-互动");
  15. text.setTextColor(Color.RED);
  16. text.setTextSize(25);
  17. text.setGravity(Gravity.CENTER);
  18. return text;
  19. }
  20. }























































6.侧边栏菜单详情页

标签:

原文地址:http://www.cnblogs.com/liuyu0529/p/4915710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!