首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PagerTabStrip正在裁剪图标

PagerTabStrip正在裁剪图标
EN

Stack Overflow用户
提问于 2017-10-19 09:06:42
回答 1查看 69关注 0票数 1

这个设计要求在PagerTabStrip的标签上只有一个图标。

下面是XML:

代码语言:javascript
复制
<android.support.v4.view.PagerTabStrip
        android:id="@+id/tbstrp_album"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:foregroundGravity="bottom"
        android:padding="0dp"
        android:background="@color/offWhite">

下面是我在适配器中的getPageTitle:

代码语言:javascript
复制
@Override
public CharSequence getPageTitle(int position) {
    // This is "generic" string that we will use as the title to be replaced.
    String title = "title";

    Drawable myDrawable = oContext.getDrawable(R.drawable.alpha);

    // initiate the SpannableString builder
    SpannableStringBuilder spanBuilder = new SpannableStringBuilder(title); // space added before text for convenience

    // set the drawable's size...if it could be too big or too small for display
    myDrawable.setBounds(0, 0, 50, 50);

    // turn the Drawable into ImageSpan and align it along the baseline
    ImageSpan imageSpan = new ImageSpan(myDrawable, ImageSpan.ALIGN_BASELINE);

    // CRUCIAL: this is where we replace the "title" w/ the image
    // 0: we start from the beginning
    // title.length(): we are replacing the entire string
    // the last flag doesn't do anything in our case
    spanBuilder.setSpan(imageSpan, 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanBuilder;
}

输出如下所示:

是什么原因导致条带裁剪图像?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2017-10-28 11:51:23

事实证明这句话才是罪魁祸首:

myDrawable.setBounds(0,0,50,50);

我把第二个参数"top“改成了30,图标没有被裁剪。

未回答的问题是still...why我是否必须为"top“参数指定值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46821443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档