【发布时间】:2015-02-12 05:56:08
【问题描述】:
我正在使用SlidingTabLayout创建选项卡布局,问题是,它使用spannableString,并且图标在字符串的左侧,而我想要实现的是图标在字符串的顶部
这里是标签 xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground"
android:gravity="center"
android:padding="5dp"
android:textSize="15sp"
android:textStyle="bold" />
这里是 Java
SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
slidingTabLayout.setCustomTabView(R.layout.custom_tab, 0);
并且在自定义的 FragmentPagerAdapter 中:
@Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
//return tabTitles[position];
Drawable image = context.getResources().getDrawable(R.drawable.ic_launcher);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
// Replace blank spaces with image icon
SpannableString sb = new SpannableString(" " + tabTitles[position]);
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BASELINE);
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}
感谢您的帮助
【问题讨论】:
标签: android android-layout android-viewpager android-imageview textview