0

I am using a ViewPager for swipe tabs in my application. The viewpager displays 3 tabs, the current, the previous and the next. Now, I want to make the current tab bigger than the previous and next tab.

Is this possible? Setting the PagerTitleStrip textSize sets the textSize for all 3 tabs.

I think I'll need a custom viewpager layout, but I don't know how to do this.

I want to make 'ROOM 5' bigger and the other 2 small I want to make 'ROOM 5' bigger and the other 2 small

Code used right now:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:id="@+id/pager"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context=".RoomViewActivity" 
    >  


    <android.support.v4.view.PagerTitleStrip  
        android:id="@+id/pager_title_strip"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:layout_gravity="top"  
        android:paddingBottom="20dp"  
        android:paddingTop="20dp"  
        android:textColor="#fff" 

        />  


</android.support.v4.view.ViewPager> 

1 Answer 1

4

You can't individually adjust the size of a particular TextView in the PagerTitleStrip without adjusting the size of the rest. So, if you want use the PagerTitleStrip indicator the best way to adjust that text size is to use a RelativeSizeSpan. Here's a quick example of doing that:

private CharSequence relativeSizeSpan(CharSequence source, int pos) {
    if (mViewPager.getCurrentItem() != pos) {
        return source;
    }
    final SpannableString ss = new SpannableString(source);
    ss.setSpan(new RelativeSizeSpan(2f), 0, source.length(), 0);
    return ss;
}

    // //////////////////////////////////////////////////////////////////////////
    // In your PagerAdapter
    // //////////////////////////////////////////////////////////////////////////

@Override
public CharSequence getPageTitle(int pos) {
    switch (pos) {
        case 0:
            return relativeSizeSpan(zero, pos);
        case 1:
            return relativeSizeSpan(one, pos);
        case 2:
            return relativeSizeSpan(two, pos);
        default:
            break;
    }
    return null;
}

Otherwise you might look into copying over the source of the PagerTitleStrip to edit it as you see fit or use an alternative third party indicator like viewpagerindicator.

Here's a screenshot from the above example using a RelativeSizeSpan.

Example

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.