Grid layout within tabs

前端 未结 2 1919
予麋鹿
予麋鹿 2021-01-24 02:04

I\'m new to Android and therefore faced such problem.

How can I change layout from: \"enter

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 02:18

    Answer Given By rogcg is very good and nice. But the Images for each fragment is same. I like to add some codes in the mainactivity which has viewpager.I think we can use fragment instead of activity, Here is the code.The same code as the Main Activity given by rogcg. Add these codes too.
    In Layout for mainfragment add ActionBarlayout,toolbar and slidingtablayout
    In Mainfragment,add 
      private List mFragments = new Vector();
     in oncreate(), create three fragments , 
        mFragments.add(new HomeFragment());
        mFragments.add(new Title1());
        mFragments.add(new Title2());
        mFragments.add(new Title3());
      in onCreateView(),add 
          mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
        mViewPager.setAdapter(mSectionsPagerAdapter);
        tabLayout = (SlidingTabLayout) v.findViewById(R.id.tabanim_tabs);
        tabLayout.setViewPager(mViewPager);
      in SectionPageAdapter class,add
        @Override
        public Fragment getItem(int position) {
    
            return mFragments.get(position+1);
        }
    
        @Override
        public int getCount() {
    
            return 3;
    
        }
    
        @Override
        public CharSequence getPageTitle(int position) {
          Locale l = Locale.getDefault();
            switch (position)
            {
                case 0:
                    return getString(R.string.English).toUpperCase(l);
                case 1:
                    return getString(R.string.Tamil).toUpperCase(l);
                case 2:
                    return getString(R.string.Hindi).toUpperCase(l);
            }
            return null;
    
        }
     Now add any view in Title1() fragment as you usage and add any things in it I think this message was useful. please vote for me. Thank you.
    

提交回复
热议问题