Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a shape drawable together with an image?

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!

like image 505
Surya Wijaya Madjid Avatar asked Jun 07 '11 10:06

Surya Wijaya Madjid


People also ask

How do you insert a picture into drawable?

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 do you make a drawable shape?

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.


1 Answers

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> 
like image 119
woodshy Avatar answered Sep 17 '22 02:09

woodshy