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


- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01