Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

imageview - How can i develop the PagerSlidingTabStrip with images in android?

I am using the PagerSlidingTabStrip in myapp .In this titles are setting fine but images are not setting tabstrip .I searched alot in google but didn't get the correct result.But this is very important for me.

Please see screenshot below enter image description here

Advance thanks to all.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was also interested doing same as yours, Finally I did it for you.

Import 'SlidingTabsBasic' demo from android-sdk sample or download it from google android samples from Here.

1.create custom_tab.xml with only a TextView 2.In 'SlidingTabsBasicFragment.class' do below changes:

-add this code in onViewCreated()

mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setCustomTabView(R.layout.custom_tab, 0);
mSlidingTabLayout.setViewPager(mViewPager);

-in SamplePagerAdapter class, replace this function code

public CharSequence getPageTitle(int position)
{
    //return "Item " + (position + 1);
    Drawable image = getActivity().getResources().getDrawable(imageResId[position]);
    image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
    SpannableString sb = new SpannableString(" ");
    ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
    sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return sb;
}

If you have done it properly, You will get something like this:

Tab Strip

Hope this will help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...