![]() Public final Context final AttributeSet attrs, Public final Context context, final AttributeSet attrs) Private boolean mGravityAndModeSeUpNeeded = true Public class AdaptiveTabLayout extends TabLayout Don't set any mode or gravity on the xml.ĪdaptiveTabLayout.java import Layout width needs to be wrap_content on the xml.Deals with the different passes on the onLayout phase in order to.This means works well with translations because doesn't assume any tab size, the tabs get measure. This works with real screen sizes and real tab sizes. It gets real measures and doesn't make any assumptions (like screen is 360dp wide or whatever.).See different text sizes or oven two lines of text in some tabs, which You don't handle this case it's gonna happen on some devices you'll Room for MODE_SCROLLABLE but not enough room for MODE_FIXED. This was the only way I found to actually solve the problem, answer the question and avoid/workaround problems that other answers here don't. I created an AdaptiveTabLayout class to achieve this. ViewGroup.LayoutParams mParams = mTabLayout.getLayoutParams() If(mTabLayout.getWidth() < ().getDisplayMetrics().widthPixels) Runnable mTabLayout_config = new void run() MTabLayout.addTab(mTabLayout.newTab().setText("Customer Detail")) MTabLayout.addTab(mTabLayout.newTab().setText("Calendar")) MTabLayout.addTab(mTabLayout.newTab().setText("Booking/Sampling")) MTabLayout.addTab(mTabLayout.newTab().setText("Signature")) MTabLayout.addTab(mTabLayout.newTab().setText("Dashboard")) ![]() MTabLayout = (TabLayout)findViewById(R.id.tab_layout) MToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar) Oncreate void onCreate(Bundle savedInstanceState) I made small changes of Velasco's solution on the runnable part: Is there any way to set gravity and mode dynamically (and to see what I am expecting)?ĮDITED: This is the Layout of my TabLayout: Why is GRAVITY_CENTER not working for SCROLLABLE if the tabLayout fits the screen? This is what I would expect for landscape but to have this, I need to set MODE_FIXED, so what I get in portrait is: ![]() So it is using SCROLLABLE in both orientations, but it is not using GRAVITY_CENTER. So GRAVITY_FILL is compatible only with MODE_FIXED but, at is doesn't specify anything for GRAVITY_CENTER, I expect it to be compatible with MODE_SCROLLABLE, but this is what I get using GRAVITY_CENTER and MODE_SCROLLABLE In touch interfaces when users don’t need to directly compare the tab Subset of tabs at any given moment, and can contain longer tab labelsĪnd a larger number of tabs. Public static final int MODE_SCROLLABLE Scrollable tabs display a Fixed tabs have equal width, based on the widest tab The maximum number of tabs is limited by the ![]() Public static final int MODE_FIXED Fixed tabs display all tabsĬoncurrently and are best used with content that benefits from quick Public static final int GRAVITY_FILL Gravity used to fill the Public static final int GRAVITY_CENTER Gravity used to lay out the So I expect that if there is no room, the tabLayout is scrollable, but if there is room, it is centered. I am dealing with Gravity and Mode setting my tabLayout as: tTabGravity(TabLayout.GRAVITY_CENTER) I want the layout to adapt to every screen size and orientation, but it can be seen correctly in one orientation. I am trying to use the new Design TabLayout in my project. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |