Shape Drawable Size not working

I have a very simple shape that I want to set the width of:

<shape android:shape="rectangle">
    <solid android:color="@color/orange"/>
    <size android:width="2dp"/>

However, when I assign this to the background of a EditText it just shows an orange background instead of a rectangle of width 2dp. Why isn’t setting the size working? I want to create a transparent drawable with a orange rectangle on the left side. I also have this wrapped in a selector:

  • Volley JsonObjectRequest Post request not working
  • Incorrect items sizing in layer-list on pre-lollipop
  • What happens if a Service is started multiple times?
  • Unable to use Fragments with Android Compatibility Package
  • Sharedpreference byte value cleared after app killed via 'Force Stop' or task manager
  • Is there a way to add a badge to an application icon in Android?
  • <selector xmlns:android="">
        <item android:state_focused="true">
            <shape android:shape="rectangle">
                <solid android:color="@color/orange"/>
                <size android:width="2dp" android:height="6dp"/>
            <shape android:shape="rectangle">
                <solid android:color="@android:color/transparent"/>

    I’ve tried adding height just to see if it would change the size. It doesn’t. It’s like its completely ignoring the size. WTF?

    Related posts:

    Can you use the merge tag with fragments?
    Can&#039;t add library to my android project
    Android: publish an app with different screenshots corresponding to different languages?
    Getting default padding for AlertDialog
    Webview not able to load https url in android?
    Building FFMPEG with librtmp for android
  • color value drawable resource issue
  • Why Images.Media.insertImage return null
  • How to center toolbar back button?
  • Use an intent to send data to my activity
  • Android Push Notifications in China
  • How to mute camera shutter sound on android phone
  • 6 Solutions collect form web for “Shape Drawable Size not working”

    Just to specify the user983447’s answer – the size attribute does really mean a proportion. You should set the size for all shapes in your layer-list and it’ll be used a as a proportion when scaling – like the layout_weight attribute of LinearLayout. So it’s better to name it not a size but a weight

    Below is a work-around how to implement top and bottom white lines without using the size attribute:

    <layer-list xmlns:android="">
                <solid android:color="#fff" />
        <item android:top="1dp" android:bottom="1dp">
                <solid android:color="#888" />

    I found the layer-list to be very devious for a first time Androider because of the following. At first glance most would think item top,bottom,right,left attributes are FROM the top,bottom,right,left. Where a value of the following:

    <item android:top="10dp">

    Would net you a starting point 10dp from the top of the respective container. This is not the case. Think of it as OFF OF the top,bottom,right,left. <item android:top="10dp"> will still net you a starting point 10dp OFF OF the top, but what happens when you want to set the bottom?

    <item android:bottom="20dp">

    This will not get you a bottom at 20dp from the TOP, rather a bottom of 20dp OFF OF the BOTTOM of the container.

    So, for example with a 100dp container, if you wanted a rectangle with a top edge starting at 20dp and a bottom edge at 40dp:

    <item android:top="20" android:bottom="60dp">

    I had similar problem.

    Documentation ( ) says:


    The size of the shape.

    Note: The shape scales to the size of the container View proportionate to the dimensions defined here, by default. When you use the shape in an ImageView, you can restrict scaling by setting the android:scaleType to “center”.

    If I understand correctly, it means that “size” tag is not for setting size but for setting proportions.

    shape’s size attribute will provide the value for drawable.getIntrinsicWidth & getIntrinsicHeight.

    if the drawable’s container(e.g. ImageView, TextView) has the layout param WRAP_CONTENT, then the container dimension will change if the drawable drawingState change.

    but there are a bug in android framework in ImageView drawingState implementation

    ImageView only update/resize its dimension by the drawable dimension on state_selected but don’t on state_activated

    It can work with a foreground. It seems like you can’t set a background’s gravity. But you can on a foreground. I checked API 21, 23 and 24 (well, with the Studio design preview) and the following places a solid circle dot on the ImageView.

    <shape android:shape="oval" xmlns:android="">
        <solid android:color="@color/colorPrimary" />
        <size android:height="8dp" android:width="8dp" />

    With the layout snippet


    UPDATE: While it appears to work in the layout design tool, it doesn’t look the same in the emulator.

    used this.

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android=""
    android:shape="rectangle" >
        android:width="1dip" />
        android:topRightRadius="0.1dip" />
    <solid android:color="@color/White" />

    put this rectangle.xml to drawable.and set your view background.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.