为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

2 回答

private void initView() {

    mViewPager = (ViewPager) findViewById(R.id.viewpager);

    mTabWeChat = (LinearLayout) findViewById(R.id.tab_wechat_ll);
    mTabFriend = (LinearLayout) findViewById(R.id.tab_friend_ll);
    mTabAddress = (LinearLayout) findViewById(R.id.tab_address_ll);
    mTabSetting = (LinearLayout) findViewById(R.id.tab_settings_ll);

    mBtnWeChat = (ImageButton) findViewById(R.id.tab_wechat_btn);
    mBtnFriend = (ImageButton) findViewById(R.id.tab_friend_btn);
    mBtnAddress = (ImageButton) findViewById(R.id.tab_address_btn);
    mBtnSetting = (ImageButton) findViewById(R.id.tab_settings_btn);

    LayoutInflater mInflater = LayoutInflater.from(this);
    View tab01 = mInflater.inflate(R.layout.tab1_main, null);
    View tab02 = mInflater.inflate(R.layout.tab2_main, null);
    View tab03 = mInflater.inflate(R.layout.tab3_main, null);
    View tab04 = mInflater.inflate(R.layout.tab4_main, null);

    mViews.add(tab01);
    mViews.add(tab02);
    mViews.add(tab03);
    mViews.add(tab04);


    mAdapter = new PagerAdapter() {

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(mViews.get(position));// 移除view
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = mViews.get(position); // 初始view
            container.addView(view);
            return view;

        }

        @Override
        public int getCount() {
            return mViews.size(); // 获取view大小
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    };


    mViewPager.setAdapter(mAdapter);
}

你可以参照这个代码检查下。

0 回复 有任何疑惑可以回复我~
#1

qq_L_571 提问者

好的,谢谢
2017-01-10 回复 有任何疑惑可以回复我~

检查下代码吧,

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
多种多样的App主界面Tab实现方法
  • 参与学习       48934    人
  • 解答问题       179    个

本课程就将讲解迄今为止最流行的4种实现Tab的方法

进入课程

为什么不显示TAB的内容呢

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信