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.

ConstraintLayout in snapshot image using `match_parent` instead of `wrap_content`

See original GitHub issue

Actual:

This is an image

Expected:

Screen Shot 2022-02-01 at 12 03 16 PM
XML (click to expand)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/banner_root"
    android:layout_width="match_parent"
    android:visibility="gone"
    tools:visibility="visible"
    android:layout_height="wrap_content"
    android:paddingLeft="18dp"
    android:paddingStart="18dp"
    android:paddingTop="16dp"
    android:paddingRight="16dp"
    android:paddingEnd="16dp"
    android:paddingBottom="20dp">

    <ImageView
        android:id="@+id/imageview_empty_logo"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="@id/textview_empty_description"
        tools:srcCompat="@drawable/ic_indicator_warning_yellow"/>

    <TextView
        android:id="@+id/textview_empty_description"
        style="@style/TextNormalBlack"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@id/textview_banner_action"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/imageview_empty_logo"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="spread"
        tools:text="@tools:sample/lorem"
        tools:textColor="@color/text_normal"/>

    <TextView
        android:id="@+id/textview_banner_action"
        style="@style/TextNormalBold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textview_empty_description"
        tools:text="@android:string/ok"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Test File (click to expand)
        val root = paparazzi.inflate<ConstraintLayout>(R.layout.component_banner)
        root.isVisible = isShown
        val bannerRoot = root.findViewById<ConstraintLayout>(R.id.banner_root)
        bannerRoot.background = ContextCompat.getDrawable(root.context, background ?: 0)
        val imageviewEmptyLogo = root.findViewById<ImageView>(R.id.imageview_empty_logo)
        imageviewEmptyLogo.isVisible = logo != -1
        imageviewEmptyLogo.setImageDrawable(
            ContextCompat.getDrawable(
                root.context,
                logo ?: 0
            )
        )
        val textviewEmptyDescription = root.findViewById<TextView>(R.id.textview_empty_description)
        textviewEmptyDescription.text = description
        textviewEmptyDescription.setTextColor(
            ContextCompat.getColor(
                root.context,
                descriptionColor ?: 0
            )
        )
        val textviewBannerAction = root.findViewById<TextView>(R.id.textview_banner_action)
        textviewBannerAction.text = okText
        textviewBannerAction.setTextColor(
            ContextCompat.getColor(
                root.context,
                okTextColor ?: 0
            )
        )

        paparazzi.snapshot(root)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
BenedictPcommented, Aug 18, 2022

It’s possible to use the snapshot method for composables from Paparazzi to easily wrap the ConstraintLayout view under test into a column so the height is not the device height anymore. Like:

fun method() {
  val yourView = paparazzi.inflate<ConstraintLayout>(R.layout.your_view)
  paparazzi.snapshot {
    Column {
      AndroidView(modifier = Modifier.fillMaxWidth(), factory = {
        yourView
      })
    }
  }
}

But the margins of the ConstraintLayout are gone 😦

0reactions
BenedictPcommented, Dec 16, 2022

It’s now working, but margins around the view are not there: image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrap_content view inside a ConstraintLayout stretches ...
Wrap_content view inside a ConstraintLayout stretches outside the screen · can you post the text view along with its parent constraint layout? as ......
Read more >
why not work in constraint layout · Issue #320 - GitHub
i dot know why my layout not show circle image view ?
Read more >
ConstraintLayout: NEVER EVER! - Rami Jemli
ConstraintLayout supports the “0dp” value (match_constraint) instead of “match_parent” to get the match parent behavior. So, NEVER EVER use “match_parent” ...
Read more >
Understanding the Constraint Layout in Android - Dev Genius
b) WRAP_CONTENT : The widget with its dimension set to WRAP_CONTENT takes only the space that is needed. But while using WRAP_CONTENT, sometimes ......
Read more >
Android ConstraintLayout explained using a complex UI
Android ConstraintLayout explained using a complex UI · TextView android:id="@+id/tvnumber" android:layout_width="wrap_content" android:layout_height=" ...
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