How to get gravity 'bottom' working on a drawable in xml

how to calculate gravity of a planet
force of gravity on earth
gravitational constant
gravity formula
acceleration due to gravity
force of gravity units
force of gravity calculator
gravity equation

I have a simple aim. I want a light grey background on my FrameLayout with a black dividing line underneath it (only undernearth, not all around). So far I have this:

<?xml version="1.0" encoding="utf-8"?>
   <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
   <item>
    <shape android:shape="rectangle" android:gravity="center">
        <solid android:color="#EEEEEE" />   
    </shape>
   </item>
   <item>
   <shape android:shape="line" android:gravity="bottom" >
       <stroke android:width="1dip" android:color="#010101"/>
   </shape>
   </item>
   </layer-list>

But it draws the line through the centre, i.e. ignores the gravity='bottom' bit. How can I fix this?

EDIT: This question is very old. The selected answer may or may not be in-line with current APIs, etc. You are encouraged to start your own question rather than add to this one, which is no longer monitored.

I'd recommend using a nine-patch image for this - here's an example that should do the job:

(It's only tiny but it is there!) If you place this in your drawable folder and set your FrameLayout's background to it then you should get the desired result. The content will go in the grey area and the #010101 pixel will be stretched horizontally to form a line at the bottom. Just make sure to keep the .9.png extension to ensure it gets loaded as a nine-patch.

Hope that helps you

Gravity, Kilograms and slugs are units of mass; newtons and pounds are units of weight. You can use Newton's law of gravitation to get the acceleration due to gravity, g,  Gravity is what holds the planets in orbit around the sun and what keeps the moon in orbit around Earth. The gravitational pull of the moon pulls the seas towards it, causing the ocean tides. The gravitational pull of the moon pulls the seas towards it, causing the ocean tides.

I've struggled a lot with this as well. Basically, to create a border at the bottom, you have to think in opposite direction from what you expect. You start with a rectangle with your Border color. On top of that, you draw the actual color, with an offset from the bottom. I use this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- CREATE A RECTANGLE WITH YOUR BORDER COLOR -->
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#fff"/>
        </shape>
    </item>

    <!-- NOW DEFINE THE NORMAL COLOR-->
    <item android:bottom="BOTTOM_BORDER_THICKNESS E.G. 4dp">
        <shape android:shape="rectangle" >
            <solid android:color="#ccc"/>
        </shape>
    </item>
</layer-list>

Or, as Juan Pablo Saraceno suggested :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item> 
        <color android:color="YOUR_BORDER_COLOR" /> 
    </item> 
    <item android:top="YOUR_BORDER_THICKNESS"> 
        <color android:color="YOUR_BG_COLOR" /> 
    </item> 
</layer-list>

How to Calculate the Force of Gravity on the Earth's Surface, where the universal gravitation constant G = 6.67 × 10-11 N m2/kg2. Gravity Explained. The magnitude g of the gravitational field of any "massive" object (that is, a  To calculate specific gravity, you divide the density of the substance by the density of water at 4 degrees Celsius, since water achieves its maximum density at this temperature. In CGS (centimeter, gram, second) metric units, the density of water is essentially 1 gram/cubic centimeter, so in these units,

Unfortunately I have not found a way to get the gravity working for drawables, but I found how you can achieve what you want with pure xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="-2dp"
        android:left="-2dp"
        android:right="0dp"
        android:bottom="1dp"
        >
        <shape android:shape="rectangle">
            <solid android:color="#EEEEEE"/>
            <stroke android:width="1dp" android:color="#010101"/>
        </shape>
    </item>
</layer-list>

Good luck:)

How to Calculate Force of Gravity, The gravitational field strength - g - describes the amount of force exerted upon That is to say, the acceleration of gravity on the surface of the earth at sea level  Every time you jump, you experience gravity. It pulls you back down to the ground. Without gravity, you'd float off into the atmosphere -- along with all of the other matter on Earth. You see gravity at work any time you drop a book, step on a scale or toss a ball up into the air.

This works!

<item>
      <bitmap
         android:gravity="left|bottom"
         android:src="@drawable/myDrawable" />
 </item>

The Value of g, How to use the gravity formula? Find out the mass of the first object. Let's choose Earth - its mass is equal to 5.972 * 1024 kg. Gravity (from Latin gravitas, meaning 'weight'), or gravitation, is a natural phenomenon by which all things with mass or energy—including planets, stars, galaxies, and even light —are brought toward (or gravitate toward) one another. On Earth, gravity gives weight to physical objects, and the Moon's gravity causes the ocean tides.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/Black" />
        </shape>
    </item>
    <item android:bottom="5dp">
        <shape android:shape="rectangle" >
            <solid android:color="@color/White" />
        </shape>
    </item>

</layer-list>

Calculating the Gravitational Force, Objects with more mass have more gravity. Gravity also gets weaker with distance. So, the closer objects are to each other, the stronger their gravitational pull is. I think that there should be a block that could create artifical gravity on the space stations because I get very annoyed when I try to go up stairs and I jump 50 blocks in the air. #1 The Unipotatoe , Mar 27, 2013

Gravitational Force Calculator, The Grav Professionals. Trilby Media is a development company you can turn to for help with your Grav site. Trilby offers a variety of professional services and is run by the same team that built Grav in the first place!

What Is Gravity?, At Gravity, we know you love your remote corner of the world. But even if your driveway's 5ks long, or it takes a boat ride to visit the neighbours, you still want to get online. Get Gravity, and do more from right where you are with our rural broadband packages.

Isaac Newton's Formula for the Force of Gravity: Definition ,

Comments
  • That's a good point, I could do it that way. In fact, I will but I'd still be interested to know hot to get the gravity tag working for that line - seems a lot nicer solution to me but thanks for your suggestion.
  • No mention of the gravity tag here. I can't see any way to achieve this using pure xml, you could create the ShapeDrawable in code and set its bounds based on the bounds of the layout?
  • This is a really good answer and deserves to be better positioned IMHO. I think is a bit of a shame that android doesn't support gravity the proper way and forces one to do this. It worked for me even using <color> tags instead of rectangle, shapes, so even more simple. <layer-list xmlns:android="schemas.android.com/apk/res/android" > <item> <color android:color="YOUR_BORDER_COLOR" /> </item> <item android:top="YOUR_BORDER_THICKNESS"> <color android:color="YOUR_BG_COLOR" /> </item> </layer-list>
  • The only problem is that i generates overdraw, because you are drawing a full rectangle with the color of your border only to overdraw it with the actual rectangle. Without real gravity still 9-patch wins.
  • This wont work if you need a translucent top part and a solid bottom part. So I guess I will have to work with a nine-patch?
  • <item> <bitmap android:gravity="left|bottom" android:src="@drawable/myDrawable" /> </item>
  • Nop it doesn't for ShapeDrawable because it is a drawable, not a Bitmap.
  • This solution works like a charm, because using the "put a rectangle covering the stroke of the other rectangle" solution left me sometimes with a tiny 1 pixel border on the right of the text boxes.
  • Doesn't work for API 21. Bottom line just got stretched to full height
  • Just tested on API 22 and it doesn't work. Looks properly in the Android Studio Preview panel though.