Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7777105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:03:15+00:00 2026-06-01T18:03:15+00:00

Trying to use LayerDrawable (defined in XML as layer-list) to layer several shape drawables

  • 0

Trying to use LayerDrawable (defined in XML as layer-list) to layer several shape drawables onto one another; to be used as a background for a layout.

The Android guide (for LayerList) says:

All drawable items are scaled to fit the size of the containing View,
by default. Thus, placing your images in a layer list at different
positions might increase the size of the View and some images scale as
appropriate. To avoid scaling items in the list, use a <bitmap>
element inside the <item> element to specify the drawable and define
the gravity to something that does not scale, such as “center”.

I don’t want my shapes to scale, but I’m unsure how to wrap them in bitmap tags correctly: it produces an error if I do it as follows:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap
            android:src="@drawable/layer_one"
            android:gravity="center" />
    </item>
    <item>
        <bitmap
            android:src="@drawable/layer_two"
            android:gravity="center" />
    </item>
    <item>
        <bitmap
            android:src="@drawable/layer_three"
            android:gravity="center" />
    </item>
    <item>
        <bitmap
            android:src="@drawable/layer_four"
            android:gravity="center" />
    </item>
</layer-list>

Complaining:

Binary XML file line #25: <bitmap> requires a valid src attribute

An example of one of the drawables, e.g. res/drawable/layer_one.xml:

<?xml version="1.0" encoding="utf-8"?>

<!--  res/drawable/layer_one.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#FFFFFF"/>
    <corners
        android:bottomRightRadius="15dp"
        android:bottomLeftRadius="15dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp" />
</shape>

The example used on the Android site uses images as drawables, not XML-defined shapes (not to say that my error is specific to these, and that I haven’t made a silly mistake somewhere). Any clues appreciated, thanks.


Using drawable resources
This question’s answer states that you cannot use an XML drawable as the src for a Bitmap. I’ve amended the title of the question, to now ask how you can prevent shapes from scaling (thereby resizing the container view) without using bitmap, or am I forced to use actual image resources?


Added an image of the desired outcome – the ability to have a background with a regular rectangle filled shape or whatever, and then layered on top of this, more shape drawables (here there are 3 ellipses). On the left is ideal, where top and left offsets are allowed, and on the right is fine, where all shapes just go to a default position:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:03:16+00:00Added an answer on June 1, 2026 at 6:03 pm

    Yes, (as per my previous answer) you cant use xml drawable for bitmaps. It is fine to build, but when you run the app, it crashes.

    Regarding the statement use a <bitmap> element inside the <item> element means that you can define further shapes in your layer-list and that’s what it is for. Though you can also define Bitmaps but then your bitmaps should have a src value referring to solid image (not xml).

    What you can do is to insert the layer_one, layer_two and other layer’s xml into your layer_list xml. For example:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item>
            <shape
                android:shape="rectangle" >
                <solid android:color="#FFFFFF" />
    
                <corners
                    android:bottomLeftRadius="15dp"
                    android:bottomRightRadius="15dp"
                    android:topLeftRadius="15dp"
                    android:topRightRadius="15dp" />
            </shape>
        </item>
    
        <!-- and so on with your other shapes -->
    
    </layer-list>
    

    Hope it should work 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying use make a div's background transparent using a mixture of CSS3 rgba()
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use WMI to obtain a list of installed programs for Windows XP.
I am trying use the django ORM to get a list by year of
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I am trying use a Java Uploader in a ROR app (for its ease
Hi I'm trying use a datepicker on a field I have. I'm trying to
Trying to use this method (gist of which is use self.method_name in the FunnyHelper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.