Home > database >  Add a background Image in Constraint Layout
Add a background Image in Constraint Layout

Time:02-20

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>

CodePudding user response:

<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.

  • Related