我怎样才能开发与Android的图像PagerSlidingTabStrip? [英] How can i develop the PagerSlidingTabStrip with images in android?

查看:217
本文介绍了我怎样才能开发与Android的图像PagerSlidingTabStrip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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:

希望这将帮助!

这篇关于我怎样才能开发与Android的图像PagerSlidingTabStrip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆