Android TabPage Indicator content wrapping issue
Asked Answered
C

5

9

I've encountered another issue with ViewPager and I can't solve it with my current knowledge right now.

I have TabPageIndicator with ViewPager and on every tab, I'm showing text. It's simple textView:

<?xml version="1.0" encoding="utf-8"?>
<view xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    class="viewpagerindicator.TabPageIndicator$TabView" >

    <TextView
        android:id="@+id/vpi_tab_text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:gravity="center"
        android:paddingBottom="10dip"
        android:paddingLeft="8dip"
        android:paddingRight="8dip"
        android:paddingTop="10dip"
        android:textColor="@drawable/vpi_tab_text_color"
        android:typeface="serif" />

</view>

I want the text in the tab to be always a single line and to be always whole text, not ellipsize, no wrapping, no more than 1 line. It's required for the user to be able to read it whole...

But I can't do that, I've tried different options and I still encounter some problems - either the text has more than just one line, but only the first one is displayed, or only a part of the text is displayed.

Have you experienced something similar?

Any help is appreciated

EDIT ONE:

I believe that the problem is here:

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY;
setFillViewport(lockedExpanded);
    final int childCount = mTabLayout.getChildCount();
    if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
        if (childCount > 2) {
            mMaxTabWidth = (int) (MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
        } else {
            mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
        }
    } else {
        mMaxTabWidth = -1;
    }

    final int oldWidth = getMeasuredWidth();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    final int newWidth = getMeasuredWidth();

    if (lockedExpanded && oldWidth != newWidth) {
        // Recenter the tab display if we're at a new (scrollable) size.
        setCurrentItem(mSelectedTabIndex);
    }
 }

mMaxTabWidth...

Cateyed answered 28/6, 2012 at 10:13 Comment(0)
C
4

I think the issue was simple, I commented out this part:

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);

            // Re-measure if we went beyond our maximum size.
//          if (mParent.mMaxTabWidth > 0 && getMeasuredWidth() > mParent.mMaxTabWidth) {
//              super.onMeasure(MeasureSpec.makeMeasureSpec(mParent.mMaxTabWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
//          }
        }

Now it works the way I wanted... I was looking at the wrong parts of the code all the time.

Cateyed answered 28/6, 2012 at 11:5 Comment(0)
A
1

I was having problems with it ellipsizing text in the tabs when it shouldn't. I found the fix here, #227 using @larham's suggestion. Here's basically what he did, but it would be a good idea to read his explanation of what he did and why he did it:

In TabPageIndicator.java, replace the following:

mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));

with:

mTabLayout.addView(tabView, new LinearLayout.LayoutParams(WRAP_CONTENT, MATCH_PARENT, 1));

That fixed it for me.

Ashlaring answered 22/8, 2013 at 7:26 Comment(0)
F
0

I had a similar problem, whole text was not shown. I solved it reducing left/right style padding.

Fluorescent answered 10/10, 2012 at 6:56 Comment(0)
T
0

Instead of Layout weight=1 for the width, I used the Wrap content attribute. In the TabPageIndicator class, the addTab(int,CharSequence,int) method, replace the mTabLayout.addView with the following:

mTabLayout.addView(tabView, new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

Twinflower answered 8/1, 2013 at 9:17 Comment(0)
P
0

update the ViewPageIndicator Library :) was officially fixed :)

Phenol answered 13/9, 2013 at 7:58 Comment(1)
the question was: "Have you experienced something similar? Any help is appreciated" .. i had the same problem, and it was fixed to pull the newest version from the git repo. so why not?Phenol

© 2022 - 2024 — McMap. All rights reserved.