【问题标题】:PagerTabStrip is clipping off the iconPagerTabStrip 正在剪掉图标
【发布时间】:2017-10-19 01:06:41
【问题描述】:

设计要求只在 PagerTabStrip 的选项卡上显示图标。

这是 XML:

<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:

@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;
}

输出如下:

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

【问题讨论】:

    标签: android pagertabstrip


    【解决方案1】:

    原来这句话是罪魁祸首:

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

    我将第二个参数“top”更改为 30,并且图标没有被剪裁。

    悬而未决的问题仍然是......为什么我必须为“top”参数指定一个值。

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 2010-12-17
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      相关资源
      最近更新 更多