Q:

Drawing a line on top of a button in Android?

I am messing around with a calendar application in Android and would like to be able to lines over the top of a button or place an image over the button at a specific Y location. Is there a way to do this? I don't think the normal drawables (left,top,right,bottom) will give me the positioning I'm looking for.
Thanks!

UPDATE: 
Here are the results of the code below for drawing a line on a button drawable. What I had to do was give the button a transparent png image for the top drawable in the XML code. Without it, it wouldn't work. 
One of the problems I see here is I am quite limited to just a few lines. One of the replies said something about stacking buttons on a framelayout but not sure I follow. Will have to experiment some more. 
Any way to draw on the whole button instead of just the small drawable areas?

package com.test.buttondraw;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.Button;

public class ButtonDrawTestActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate (Bundle savedInstanceState)
    {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.main);

        Button b1 = (Button) findViewById (R.id.button1);

        // get the second array element (0 based) which is the top drawable
        BitmapDrawable d = (BitmapDrawable) b1.getCompoundDrawables ()[1];

        if (d != null)
        {   // thanks to dbrettschneider for bitmap code sample
            Bitmap b1src = d.getBitmap ();
            Bitmap tmp = Bitmap.createBitmap(b1src.getWidth(), b1src.getHeight(), b1src.getConfig());
            BitmapDrawable bd = new BitmapDrawable (tmp);
            bd.setBounds (d.getBounds ());

            Canvas c = new Canvas(tmp);

            Paint p = new Paint();
            p.setAntiAlias(true);

            c.drawBitmap (b1src, 0, 0, p);

            // set thickness of line
            p.setStyle (Style.STROKE);
            p.setStrokeWidth (5);

            // colors to use for each y position
            int [] clr    = {Color.BLACK,     Color.RED,     Color.GREEN, 
                                  Color.MAGENTA, Color.WHITE, Color.YELLOW, 
                                  Color.CYAN,        Color.BLUE,   Color.DKGRAY };
            int ypos = 10;

            // draw a different colored line for each element in the ypos array
            for (int i = 0; i < clr.length; i++)
            {
                p.setColor(clr[i]); 
                c.drawLine (0, ypos, b1src.getWidth (), ypos, p);
                ypos += 8;
            }

            b1.setCompoundDrawables (null, bd, null, null);
        }

    }

}

Here is the xml code:

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableTop="@drawable/png_transbg"
    android:maxHeight="128dp"
    android:maxWidth="128dp"
    android:minHeight="128dp"
    android:minWidth="128dp"
    android:text="Button" />

A:

Like dtmilano said, you can stack Views in a FrameLayout. So you can put a Button into it and overlay a second View. In the second View you would do your custom drawing.
However if you just want to add colored lines above the button text, it would be more elegant to follow Kevin's advice and go the layout way. I would do it like this:
<LinearLayout android:orientation="vertical"

              style="@android:style/Widget.Button"

              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
  <View android:background="#f00"

        android:layout_margin="1dp"
        android:layout_height="4dp"
        android:layout_width="match_parent"/>
  <View android:background="#0f0"

        android:layout_margin="1dp"
        android:layout_height="4dp"
        android:layout_width="match_parent"/>
  <View android:background="#00f"

        android:layout_margin="1dp"
        android:layout_height="4dp"
        android:layout_width="match_parent"/>
  <TextView android:text="Button"

            android:textAppearance="@android:style/TextAppearance.Widget.Button"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
</LinearLayout>

Of course you would add the Views that represent the lines dynamically in your code. Also you should externalize the dimension constants. To separate the lines from the button text, you could use another nested LinearLayout. Finally you could wrap that all into a custom View.
EDIT: If you want to distribute any free space to the lines, set their layout_heights to 0dp and their layout_weights to 1.

