Home > Mobile >  Using multiple sets of ViewPager + TabLayout, found that the first group can be normal use, the seco
Using multiple sets of ViewPager + TabLayout, found that the first group can be normal use, the seco

Time:10-13

Recently doing a APP, on my home page and classification were almost the same layout and code, but the classification of the fragment will not display, and classification of the page is very strange, the first is when he tabLayout sliding is not like home page, a slide can jump to a tab_text, he underlined will stop in the middle of the two tab_text, then will not display the content of the fragments, which is white, and sometimes in the category pages slide to slide to affect home page, page data is also set to empty or broken (that is, on the home page 2 data in page 3), but literally sliding home page will not have this kind of situation, this problem has been bothering me for two days, give some tips do method, figure below

Is this is the category pages sliding underscore between two tab_text stopped, and then display the data,
Below is the code screenshots
HomeFragment

Is bound to join the operation of the view, it is very normal, can the normal use of the
Classification the fragments of code and this is almost the same, is to join the fragments are different, and, if not in fenleiFragment manually add the TAB name will not be able to show the name of the TAB, as a whole are empty, is don't write TAB. The addTab (TAB) newTab () setText (title. Get (0))); , let him go to load, load out name, photo has been uploaded, I posted the code
The title. The add (" category a ");
Title. The add (" category 2 ");
The title. The add (" classification of three ");
Title. The add (" classified four ");
Title. The add (" category five ");
Title. The add (" classified six ");
TAB. AddTab (TAB. NewTab (). The setText (title. Get (0)));
TAB. AddTab (TAB. NewTab (). The setText (title. Get (1)));
TAB. AddTab (TAB. NewTab (). The setText (title. Get (2)));
TAB. AddTab (TAB. NewTab (). The setText (title. Get (3)));
TAB. AddTab (TAB. NewTab (). The setText (title. Get (4)));
TAB. AddTab (TAB. NewTab (). The setText (title. Get (5)));

FenleiyiFragment=new fenleiyiFragment ();
FenleierFragment=new fenleierFragment ();
FenleisanFragment=new fenleisanFragment ();
FenleisiFragment=new fenleisiFragment ();
FenleiwuFragment=new fenleiwuFragment ();
FenleiliuFragment=new fenleiliuFragment ();

Fragments could add (fenleiyiFragment);
Fragments could add (fenleierFragment;
Fragments could add (fenleisanFragment);
Fragments could add (fenleisiFragment);
Fragments could add (fenleiwuFragment);
Fragments could add (fenleiliuFragment);

Adapter=new MyFragmentPageAdapter (getFragmentManager (), title, fragments could);
Viewpager. SetAdapter (adapter);
TAB. SetupWithViewPager (viewpager);

Is the two of them with a view, I were the same, may not be able to figure has been uploaded, I posted the code
Then they view code I use is the same, will, of course, each in a different XML file
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: orientation="vertical"

The android: id="@ + id/TAB"
Android: layout_width="match_parent"
Android: layout_height="30 dp"
App: tabSelectedTextColor="@ color/word_select"
App: tabPaddingStart="5 dp"
App: tabMinWidth="70 dp"
App: tabPaddingEnd="8 dp"
App: tabTextColor="# 666666"
App: tabIndicatorColor="# FD605D"
App: tabIndicatorFullWidth="false"
App: tabMode="scrollable"


<frameLayout
Android: layout_width="match_parent"
Android: layout_height="match_parent" & gt;
The android: id="@ + id/viewpager"
Android: layout_width="match_parent"
Android: layout_height="match_parent"
Android: background="@ android: color/white/& gt;



MyFragmentPageAdapter code, should be no problem
Public class MyFragmentPageAdapter extends FragmentPagerAdapter {

Private ArrayList Tab_title;
Private ArrayList Fragments could;

Public MyFragmentPageAdapter (FragmentManager FM, ArrayList Tab_title ArrayList Fragments could) {
Super (FM);
Enclosing tab_title=tab_title;
Enclosing fragments could=fragments could;
}


@ Override
Public fragments the getItem (int position) {
Return fragments could get (position);
}

@ Override
Public int getCount () {
Return fragments could. The size ();
}

@ Nullable
@ Override
Public CharSequence getPageTitle (int position) {
Return tab_title. Get (position);
}

@ Override
Public void destroyItem (@ NonNull ViewGroup container, int position, @ NonNull Object Object) {

}
}

I am a novice, this problem has been bothering me for two days, I don't know exactly where the problem,, every brother please give advice or comments, thank you very much,





CodePudding user response:

I understand the meaning of,, you are classified in fragments and added a fragment
Give you the open source FlycoTabLayout (https://github.com/H07000223/FlycoTabLayout) this for direct use, simple and convenient
This (https://www.jianshu.com/p/2f715eedda08), which is provided by the boy go, ha, ha, ha

CodePudding user response:

By the way, that there are all you want effect: https://github.com/git-xuhao/KotlinMvp, but is written kotlin, you look for Java
  • Related