I'm using PagerSlidingTabStrip library in my application now. I have 5 tabs, so it's over screen width. so I have to scroll to see last tab.
I want to see all tabs on the screen and never wanna scroll to see other items.
I tried changing HorizontalScrollView to LinearLayout in PagerSlidingTabStrip.java but it's weird a little. Indicator moved bad.
// public class PagerSlidingTabStrip extends HorizontalScrollView
public class PagerSlidingTabStrip extends LinearLayout
and also I tried shouldExpand options is true. but it didn't work again.
app:pstsShouldExpand="true"
What can i do for this ????
I had exactly same problem but following code ,I found that if you need to set tabs shouldExpand you need to do it before setting viewpager to tabs.
tabs = (PagerSlidingTabStrip) findViewById(R.id.slidingTabStrip);
//Before setting view pager
tabs.setShouldExpand(true); //Works
tabs.setViewPager(vpPager);
//After setting view pager
tabs.setShouldExpand(true); //Will not work
I solved this problem by myself. The problem is shouldExpand Attr doesn't work because our tabs are 5 so I can't. but when I set my tab count 4, it works and looks good. They filled with device screen width.
Anyway I changed this width size.
defaultTabLayoutParams = new LinearLayout.LayoutParams(dm.widthPixels/your tab count, LayoutParams.MATCH_PARENT);
I hope it will be helpful and save your time.
Related
I have an app in which I have added TabLayout with three tabs. I want to show tab indicator from bottom to top but the problem is that when I show indicator from bottom to top tab icon also rotate.How do I resolve this issue?
mTabLayout.getTabAt(0).setCustomView(view);
mTabLayout.getTabAt(1).setIcon(tabIcons[1]);
mTabLayout.getTabAt(2).setIcon(tabIcons[2]);
mTabLayout.setRotationX(180);
I have similar requirement in my previous application
Please try below code it works perfectly for me
//First rotate the tab layout
tabOrderType.setRotationX(180);
//Find all childs for tablayout
for (int i = 0; i <tabOrderType.getChildCount() ; i++) {
LinearLayout linearList = ((LinearLayout)tabOrderType.getChildAt(i));
for(int position = 0;position<linearList.getChildCount();position++) {
//One by one again rotate layout for text and icons
LinearLayout item=((LinearLayout) linearList.getChildAt(position));
item.setBackground(getResources().getDrawable(R.drawable.custom_button_border));
item.setRotationX(180);
}
}
This is working nicely in my application and not creating any issue till now.Another way is you need to make custom tab to manage this.
Hope this helps you...if any issue please ask me...
Add this in your TabLayout XML
app:tabIndicatorGravity="top"
Please see the two screenshots :
The top part seems to be using a ViewPager. The current screen on the ViewPager shows partial of the previous and next screens.
Question : How do we achieve this animation ? i.e. where partial of the previous ane next screens can be seen ??
Just use margins/paddings in your case:
int leftRightPadding = ... ;
int margin = .... ;
viewPager.setClipToPadding(false);
viewPager.setPadding(leftRightPadding, 0, leftRightPadding, 0);
viewPager.setPageMargin(margin);
Also check JazzyViewPager or equivalent libs for zoom/fade animations.
ViewPager Background is grey. I can't find on internet any clear article that shows how to just change that background color in black for example.Any idea will be appreciated.
You can achieve it in 2 ways,
1.Add the following in your ViewPager in the xml
android:background="#000000"
2.Do it dynamically like below,
ViewPager pager= (ViewPager)findViewById(R.id.pager);
pager.setBackgroundColor(Color.BLACK);
Try this
private ViewPager mPager;
mPager = (ViewPager) view.findViewById(R.id.pager);
mPager.setBackgroundColor(Color.BLACK);
A ViewPager is not grey by default, it's transparent like other ViewGroups, so you will see your parent layout background or window background by default.
If you want to change the background color of your whole Activity, I suggest that you override the android:windowBackground attribute in your Activity's theme, which is more efficient.
You can set android:background="#android:color/transparent" to ViewPager in your xml file
and set android:background="#android:color/black" for parent layout.
I hope this will help.
I found a lot of questions about this topic, but no working answers. So I have to ask the same question again...
I have a Fragment in which I am displaying two Tabs. On smartphone devices everything looks fine. Just like I want to. But on tablets (or generally on larger screens) the two Tabs are centered, that there are two "gaps", left an right of the Tabs.
Now I want to get rid of these gaps. My favorite solution would be to stretch both Tabs to cover the complete screen width. If that is not possible, I at least want to change the color of the TabBar.
I create and add my tabs like this (I left out the text and TabListener creation and assignment):
Tab tabA;
Tab tabB;
final ActionBar myActionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
myActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
myActionBar.addTab(tabA);
myActionBar.addTab(tabB);
When I try something like this
myActionBar.getTabAt(0).getCustomView().getLayoutParams().width = 200;
I always have a NullPonterException. I also tried to use a CustomView for the tabs. I created a new TabWidget.xml Like this:
<?xml version="1.0" encoding="utf-8"?>
<TabWidget xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="match_parent"
>
</TabWidget>
But no chance. The tab size just does not change.
Just found this post: Stacked ActionBar tab bar not filling parent
It seems as if it is not possible to change the Tab width to a value bigger 160 dip. So for the moment I have to use plan b and change the color of the TabBar.
Instead of tabs, try to place image view with background image
I'm using this library for pagerSlidingTabStrip Component. I have TabStrip which occupies full screen in Portrait Orientation. But In Landscape it doesn't occupy full screen.
I'm using app1:paddingLeftRight attribute in tabstrip tag in xml, but it is not working for me. I want to setPadding programmatically for each and every device both in landscape and portrait mode. So I will place the Tabs items equally.
Any Help greatly appreciated...........
Thanks in advance
Try do this in updateTabStyles() in class PagerSlidingTabStrip in library. Something like tab.setPadding(left, top, right, bottom).
This thread might be old, however I found a solution for this. For those who are looking (still) for solution try this :
tabs.setViewPager(pager);
/*
Add top and bottom padding
*/
LinearLayout parent = (LinearLayout)tabs.getChildAt(0);
int padding = 20;
for (int i = 0; i < parent.getChildCount(); i++) {
View tab = parent.getChildAt(i);
tab.setPadding(tab.getPaddingLeft(), padding tab.getPaddingRight(), padding);
}
Put this code after setting your viewpager, or else it will read parent with 0 children.
Cheers, Happy coding.