I have this difficulty to have both rounded corner and a background image in my LinearLayout
.
I know I can achive the rounded corner by using the shape drawable XML, but if I put the shape drawable as the background of my LinearLayout
with android:background=@drawable/rounded_corner
then I cannot assign any image to be used as a background.
How can I get both a rounded corner with a background image in my LinearLayout? Any help would be appreciated. Thanks!
To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.
How to Create and Use a Shape Drawable. Creating shape drawables is done in XML with the <item> and <shape> elements. The <item> element is the enclosing parent of <shape> . It defines attributes like the width and height of the shape, but that is possible only if your project is API 23 and above.
You could use LayerDrawable, which could contain as many layers(shapes or images) as you need. You can create it either as resource or programmatically.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/rounded_corners" android:id="@+id/rounded_corners"/> <item android:drawable="@drawable/additional_image" android:id="@+id/additional_image" /> </layer-list>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With