如何在 android 中使用图像开发 PagerSlidingTabStrip?

How can i develop the PagerSlidingTabStrip with images in android?(如何在 android 中使用图像开发 PagerSlidingTabStrip?)
本文介绍了如何在 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)