1

I have a custom Relative Layout(a class extended to RelativeLayout). I draw some bitmaps on a canvas using the method dispatchDraw(). And I want to show an Edit text box on top this canvas. So I create a new instance of EditText and bring it to front. EditText adds to the layout but doesn't come to front. When I remove canvas drawing code the edit text appears. Help me if you know a way to bring the EditText to the front of the canvas.

public class EditCardLayout extends RelativeLayout {

            public EditCardLayout (Context context, AttributeSet attrs) {       
                super(context, attrs);
                this.context = context;         
                editText = new EditText(context);
                editText.setText("My Text");
                addView( editText );
                editText.bringToFront();
             }
        @Override
            protected void dispatchDraw(Canvas canvas) {
                super.dispatchDraw(canvas);
                // some bitmaps are drawn here...
            }
        }

XML :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#eceadb"
    android:gravity="center">

    <editCard.EditCardLayout
       android:id="@+id/cardEditView"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentTop="true" />

</RelativeLayout>
Kara
  • 6,115
  • 16
  • 50
  • 57
Wimansha
  • 61
  • 1
  • 7

1 Answers1

1

What order are you adding the elements in? According to the docs, the z-order is affected by the order in which the elements are drawn, with the last thing drawn on top. Try adding the edittext last.

GLee
  • 5,003
  • 5
  • 35
  • 39
  • According to my code I don't draw any EditText views. What I draw is some bitmaps which I have not presented in above code. This EditText view is added to the Relative layout which has a canvas drawn by dispatchdraw(). The problem arises between the child view and the canvas of parent Layout. – Wimansha Dec 10 '13 at 05:32
  • It's hard for me to comment without seeing the rest of the code. Can you include your draw code and your xml? Also, is there any particular reason you need to use dispatchDraw? You could try putting the bitmaps in a FrameLayout, inside your RelativeLayout, to see if it works. – GLee Dec 10 '13 at 06:50
  • As you request I added both draw & xml code. As I am doing a card editing app the essential part of the activity is done with this dispatchDraw. EditText view is used to get user inputs on to the cards. I don't think creating another FrameLayout will work. – Wimansha Dec 10 '13 at 09:37
  • Can you add the EditText in your xml file, under the EditCardLayout? – GLee Dec 10 '13 at 18:21
  • No. not like in this code I need to add many EditTexts dynamically. – Wimansha Dec 11 '13 at 11:56