简体   繁体   中英

Set Fragment Width so When Changing Fragment the other fragment show some layout Android Studio

IMAGE EXAMPLE

[so, this is the image example of my program i have 2 fragment that can be changed with swipe gesture when i at the RED layout section (u can see the image) , i can swipe to left and show the green layout

usually, the green layout is fill all the screen, but that i want here is there is some of red layout shown at the screen

i already try to change the green layout size but it didnt work, can someone help me? thanks and sorry if anyone ever ask this kind of question

]

ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new CalcTab(), "Calc");
    adapter.addFragment(new HistTab(), "History");
    viewPager.setAdapter(adapter);

the red is CalcTab and green is HistTab i want that when i change into HistTab, the CalcTab shown the 25% of its layout

Adjusting width is not the way, you can't do it like this, you must instantiate two Fragments and use a ViewPager with them. Please take a look to my article about using Fragment s and ViewPager . I think that's suitable for your case, you'll ind the gist of code as well. Take a look to the blog post

you need to add padding to your viewpager as follows.

yourViewpager.setPadding(paddingvalue, 0, paddingvalue, 0);
yourViewpager.setClipToPadding(false);

and override following method in your viewpager adapter

@Override
public float getPageWidth(int position) {
    return 0.9f;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM