Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add a background Image in Constraint Layout

I am trying to add a background image to a Constraint layout, which is the root view of my xml. The image shows if I change the layout to linear or relative but it does not show in a constraint layout. What could be the cause?

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_selected_folder_bg">

</androidx.constraintlayout.widget.ConstraintLayout>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" <--change these two lines-->
    android:layout_height="match_parent"
    android:background="@drawable/ic_selected_folder_bg">

</androidx.constraintlayout.widget.ConstraintLayout>

It is not showing since there is no content to wrap( as defined by your wrap content )as there are no views inside your viewgroup.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading