7

I have a problem with custom font in my app. Sometimes it works, sometimes not.

I have ViewPager with fragments. In fragment 2 I have LinearLayout with programmatically added TextViews. Same TextView layout added many times. On first TextView everything works fine, but on others it have problem with diacritic signs.

enter image description here

For custom fonts I use Calligraphy, but I also tried to use font family from Support Library 26 with same result. TextViews should use default font, but again when I change font in style or set typeface programmatically I end up with same result.

The problem occurs only on Android 7 (tested on Nexus 5X, Huawei P10 Lite). On Samsung Galaxy S4, Huawei Mate 10 pro - everything works fine.

Artur Latoszewski
  • 735
  • 1
  • 10
  • 21

2 Answers2

1

I found the solution. The problem was with the text itself, not with the views. The exact reason was the characters encoding. This diacritic signs wasn't in proper encoding. However it is still strange that problem occurs only on one Android version. Same text was also used on iOS, and there everything was fine.

Artur Latoszewski
  • 735
  • 1
  • 10
  • 21
0

I had a similar issue but with Italic font. It was not fitting the space and last and first item was cut off. I had to override onMeasure and add some space. I would do it like this:

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec)
    val tenPercentHeight = measuredHeight * 0.1f
    val adjustedHeight = measuredHeight + tenPercentHeight.toInt()

    setMeasuredDimension(adjustedHeight, measuredHeight)
    requestLayout()
}
Patryk Jabłoński
  • 697
  • 10
  • 29
  • The problem is with font inside of the word, not on the end. Everything is visible but polish diacritic signs are in the different font. – Artur Latoszewski May 22 '18 at 07:53
  • have you tried using different `LayoutManager`? I had also a problem with `ConstraintLayout`, the problem was different and was connected with child element height, but maybe it could have an impact on your `TextViews`. I think it is worth giving a try if it would not take whole day to reimplement – Patryk Jabłoński May 22 '18 at 09:05
  • This is not the problem with height - I've checked it. What `LayoutManager`? This is LinearLayout, not RecyclerView. – Artur Latoszewski May 28 '18 at 13:52