如何在 android 中使用图像开发 PagerSlidingTabStrip? [英] How can i develop the PagerSlidingTabStrip with images in android?

查看:15
本文介绍了如何在 android 中使用图像开发 PagerSlidingTabStrip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 myapp 中使用 PagerSlidingTabStrip .在此标题设置正常,但图像未设置 tabstrip .我在谷歌搜索了很多但没有得到正确的结果.但这对我来说非常重要.

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.

请看下面的截图

先谢谢大家了.

推荐答案

我也有兴趣做和你一样的事情,终于为你做了.

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

从 android-sdk 示例导入SlidingTabsBasic"演示或从 这里.

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

1.create custom_tab.xml 只有一个 TextView2.在 'SlidingTabsBasicFragment.class' 中进行以下更改:

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

-在 onViewCreated() 中添加这段代码

-add this code in onViewCreated()

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

-在SamplePagerAdapter类中,替换此功能代码

-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天全站免登陆