ConstraintLayout in snapshot image using `match_parent` instead of `wrap_content`
See original GitHub issueActual:
Expected:
![Screen Shot 2022-02-01 at 12 03 16 PM](https://user-images.githubusercontent.com/7057959/151915280-df24313d-3594-47e7-95b4-fd6714713836.png)
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:
- Created 2 years ago
- Reactions:1
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
But the margins of the ConstraintLayout are gone 😦
It’s now working, but margins around the view are not there:![image](https://user-images.githubusercontent.com/5817002/208051112-f3e5635d-8034-4ab3-8e40-7e12c97defed.png)