question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Width of the balloon with a custom layout not adjusted properly when setting text dynamically

See original GitHub issue

Please complete the following information:

  • Library Version 1.3.1+
  • Affected Device(s) All devices, in particular, Pixel 3a API 28

Describe the Bug: We are using Balloon.Factory() with a custom layout resource that includes several textViews. After setting text values dynamically, the width of the balloon is not resized to wrap its content (it is fixed with the initial value). As a result, the height of the content increases. The solution provided in #91 cannot be used anymore, since method measureTextWidth is private now. The issue can be easily reproduced using the demo application:

Step 1 - Add id to the TextView in the layout_custom_tag.xml:

  <TextView
    android:id="@+id/tagTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="12"
    android:textColor="@android:color/black"
    android:textSize="16sp"
    android:textStyle="bold"
    tools:ignore="HardcodedText" />

Step 2 - change the text of that tagTextView to a different value, i.e.:

customTagBalloon.getContentView().findViewById<TextView>(R.id.tagTextView).text = "Long text"

Step 3 - launch the application and click on the bottomNavBar. As a result, the height of the balloon increased, instead of the width. However, it works properly on version 1.3.0 of the library. Modified demo app to reproduce the issue is also available at: https://github.com/wkubaty/Balloon/tree/custom-layout-size-issue

Unexpected behavior on version 1.3.4:

Zrzut ekranu 2021-05-25 o 14 47 00

Expected Behavior: The width of the balloon with a custom layout should be adjusted properly when setting content dynamically.

Proper behavior on version 1.3.0:

Zrzut ekranu 2021-05-25 o 14 48 45

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
gastsailcommented, Jul 19, 2021

I found out that if you are using ConstrainLayout and have any view that has 0dp for the constrain, the lib will not adapt for what you see in the editor, instead, use match_parent or wrap_content for those views, or simply use LinearLayout

2reactions
skydovescommented, May 31, 2021

I will consider processing the changes internally. 🤔 Here is just the quick solution:

val label = customTagBalloon.getContentView().findViewById<TextView>(R.id.label)
label.text = "111111111111111111111344555"
val width = label.paint.measureText(label.text.toString())
label.maxWidth = width.toInt()
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Dynamically Change the oEmbed Width and Height in ...
Method 1. Setting Dynamic Embed Width and Height in WordPress. This method requires you to add custom code to your WordPress website. If...
Read more >
Setting text on a QLabel in a layout, doesn't resize
I've tried changing changing the size policy. The problem I have is that if the text is large, the QLabel fails to be...
Read more >
Textmesh pro is not updating when changing text ...
Text Mesh Pro is not updating text even though i use forceMeshUpdate to do it. I make a change on the text with...
Read more >
Frame Behaviors with SwiftUI
When I started using SwiftUI, one of the first modifiers I learned was .frame(width:height:alignment), and then moved to other (more ...
Read more >
How to fill a box with an image without distorting it
... that of any HTML width or height attributes. Sometimes you would like the image to completely fill the box that you have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found