Balloon icon indicating copy to clipboard operation
Balloon copied to clipboard

Height of balloon is not calculated properly with custom layout

Open scorpeeon opened this issue 10 months ago • 5 comments

Please complete the following information:

  • Library Version 1.6.11
  • Affected Device(s) - tested on multiple devices, like on emulator Pixel 9 Pro

Describe the Bug:

Hey folks, an issue I noticed is that when I set a custom layout and the height of the ballon to be wrapped:

return createBalloon(context) {
    setLayout(R.layout.tooltip)
    setHeight(BalloonSizeSpec.WRAP)

I noticed that the bottom of the text tends to get cut off. See attached screenshot: Screenshot 2025-01-10 at 18 47 29

When I include the same layout on a regular Android layout, I don't see any problems: Screenshot 2025-01-10 at 18 48 05

Sample layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/container"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#ff0077db">

    <View
            android:id="@+id/icon"
            android:layout_width="84dp"
            android:layout_height="84dp"
            android:padding="16dp"/>

    <LinearLayout
            android:id="@+id/text_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:layout_marginVertical="16dp">
        <TextView
                android:id="@+id/headline"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Sample text multiline abcqgj pjgxyz abcqgj pjgxyz"
                android:textColor="#ffffffff"
                android:textSize="17sp"/>
        <TextView
                android:id="@+id/headline_sub"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Sample text abcqgj pjgxyz abcqgj pjgxyz abcqgj pjgxyz"
                android:textColor="#ffffffff"
                android:textSize="15sp"/>
    </LinearLayout>
</LinearLayout>

The issue seems to be similar to this one: https://github.com/skydoves/Balloon/issues/372 However that issue seemed to be related to supporting multiple languages, while I'm seeing this problem even for a simple use-case, using a static layout. I don't know how the layout is constructed by the library to include the arrow icon, etc., but my feeling is that something might be off there when calculating the height in certain use-cases.

Expected Behavior: Height should be calculated properly and content should not be cut off.

scorpeeon avatar Jan 10 '25 18:01 scorpeeon

Hey @scorpeeon, this behavior is expected. To address it, you can specify the balloon width by using setWidthRatio(0.9f) for a percentage-based width or setWidth(450) for a fixed width in pixels.

skydoves avatar Jan 21 '25 01:01 skydoves

@skydoves My problem is not with the width or default lack of horizontal spacing, I know that can be added easily - my problem is about the layout content getting cut vertically. It might not be super clear from the previous image, so I'm attaching another one to point out what I mean:

Image

Is this a known issue?

scorpeeon avatar Jan 21 '25 12:01 scorpeeon

I have the same issue with large custom layouts on height.

javiercamarenatriguero avatar Jan 31 '25 13:01 javiercamarenatriguero

I also have this issue, is there any reason the height would be wrong?

AntoineGagnon avatar Mar 27 '25 14:03 AntoineGagnon

Same problem, when setting Wrap content with custom Layout it become very big, if setting correct height of 158px, in end its show balloon with 60px height.

Image

Equin avatar Apr 30 '25 16:04 Equin