我怎样才能开发与Android的图像PagerSlidingTabStrip?图像、Android、PagerSlidingTabStrip

2023-09-12 10:07:53 作者:我揽不住要走的风

我使用PagerSlidingTabStrip在MyApp的。在这个标题的设置很好,但图像没有设置标签栏。我在谷歌搜索了很多,但没有得到正确的result.But这是非常重要的我。

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

提前感谢所有。

推荐答案

我也很想做一样的你,最后我做到了你。

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

导入SlidingTabsBasic来自Android的SDK示例演示或从谷歌Android样本下载这里。

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

1,创建custom_tab.xml只有一个TextView 2.InSlidingTabsBasicFragment.class做如下修改:

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

-add这code在onViewCreated()

-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类,替换该功能code

-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:

希望这将帮助!