I have a game on the market called Memory Tutor where I am doing something similar except I am using setImageDrawable() and setBackgroundDrawable(). That way I can just change the setImageDrawable to a transparent png when I want to show the image and a white png when I want to hide it rather than drawing it the way you are trying to do.
Shawn On Jan 20, 6:16 pm, Marty Miller <[email protected]> wrote: > What is the reason for you not posting this? That took a lot of time to > write. > > On Thu, Jan 20, 2011 at 1:07 PM, MartyParty <[email protected]> wrote: > > I seem to be missing a key concept here. I want to be able to put a > > white square on top of an image. Seems simple right? I can't figure > > it out. > > > Currently, I have have an XML file describing my layout. > > > <?xml version="1.0" encoding="utf-8"?> > > <LinearLayout > > xmlns:android="http://schemas.android.com/apk/res/android" > > android:layout_height="fill_parent" > > android:layout_width="fill_parent" > > android:orientation="horizontal" > > > > <LinearLayout > > android:id="@+id/LinearLayout01" > > android:orientation="vertical" > > android:layout_height="wrap_content" > > android:layout_gravity="top" > > android:layout_width="fill_parent"> > > > <TextView > > android:layout_marginTop="5dip" > > android:layout_gravity="center" > > android:layout_height="wrap_content" > > android:id="@+id/TextView01" > > android:textSize="18sp" > > android:text="@string/title" > > android:layout_width="wrap_content"> > > </TextView> > > > <TextView > > android:layout_marginLeft="10dip" > > android:layout_marginRight="10dip" > > android:layout_marginTop="0dip" > > android:layout_gravity="center" > > android:id="@+id/TextView02" > > android:textSize="15sp" > > android:text="@string/description" > > android:layout_height="wrap_content" > > android:layout_width="wrap_content"> > > </TextView> > > > <ImageView > > android:id="@+id/profilePic" > > android:layout_marginTop="15dip" > > android:layout_gravity="center" > > android:layout_width="wrap_content" > > android:layout_height="wrap_content" > > > </ImageView> > > > </LinearLayout> > > > </LinearLayout> > > > Next, my Activity calls a method called showImage(). Using the XML, > > this method draws the picture taken with the camera along with some > > text. > > > public void showImage(Drawable d) > > { > > CropView myCropView = new CropView(this); > > ImageView myImageView = new ImageView(this); > > > setContentView(R.layout.main); > > > myImageView = (ImageView)findViewById(R.id.profilePic); > > myImageView.setImageDrawable(d); > > myImageView.setScaleType(ImageView.ScaleType.FIT_START); > > > setContentView(myCropView); > > } > > > Then I have a class CropView that extends ImageView that draws a > > square in the middle of the screen: > > > public class CropView extends ImageView { > > public CropView(Context context) { > > super(context); > > } > > @Override > > protected void onDraw(Canvas canvas) { > > super.onDraw(canvas); > > Log.d("Marty", "ON DRAW"); > > > Paint background = new Paint(); > > background.setColor(Color.RED); > > > Paint box = new Paint(); > > > box.setColor(Color.WHITE); > > box.setStyle(Paint.Style.STROKE); > > > int boxWidth = 100; > > int topX = (getWidth()-boxWidth)/2; > > int topY = (getHeight() - boxWidth)/2; > > > canvas.drawRect(topX,topY, topX+boxWidth, > > topY+boxWidth, box); > > } > > > } > > > As you can see, I have two calls to setContentView. The second call > > overlaps the other. How do I get one View to draw on top of my > > Layout? I really appreciate any help you could give. > > > Marty > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

