1

I have a little problem with my PageTabStripe. The text is not centered as well as the image is.

Here you can see a image of the problem:

enter image description here

This is how I add the images:

@Override
public CharSequence getPageTitle(int position) {

    SpannableStringBuilder sb;
    ImageSpan span;
    switch (position) {

    case 0:
        myDrawable = getResources().getDrawable(R.drawable.icon_haus);
        sb = new SpannableStringBuilder(" " + "Hauptmenü"); 

        myDrawable.setBounds(0, 0, 70, 70);
        span = new ImageSpan(myDrawable, ImageSpan.ALIGN_BOTTOM);
        sb.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        return sb;
...

And this is the XML:

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

    <android.support.v4.view.PagerTabStrip
        android:id="@+id/pts_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:textAlignment="center"
        android:background="#FFFFFF"        
        android:textColor="#000000" />

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

I hope someone could help me. :)

Zong
  • 6,160
  • 5
  • 32
  • 46
Maximus1809
  • 575
  • 1
  • 10
  • 30
  • Insteead of your last two line just set below line " sb.setSpan(new ImageSpan(myDrawable), 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);" – patel135 Apr 20 '17 at 05:14

0 Answers0