Hi,
If I want to redraw a drawable currently on screen how should I go about it?

Looking at the sample code, most seem to programaticaly define a nested
class which extends view.

The Lunar launch pad defines a separate class which extends SurfaceView and
doesn't override OnDraw();

I currently use a separate class;

In main.xml
...
<uk.ac.ic.doc.gea05.miffed.CustomView
      android:id="@+id/customView"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      />
...

public class CustomView extends View {

private Drawable droid;

public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
        Resources res = context.getResources();
        droid = res.getDrawable(R.drawable.android);
}

@Override
protected void onDraw(Canvas canvas){
        canvas.drawColor(Color.MAGENTA);
        droid.draw(canvas);
}
}

The canvas gets drawn as MAGENTA but the little droid png doesn't get drawn,
I thought it might be a Z axis issue but even without the magenta line he's
still hiding. If I set the resource as the src for an ImageView in the XML
layout then it displays fine.

Ultimately I don't know if this is the right way to go about what I want
to achieve.

Imagine you were going to write an app that displayed a picture and when you
clicked the picture it changed to a different picture, or a monochrome
version of the same picture. How would you go about it?

I don't know where the responsibility lies in the code at the moment, can I
reuse ImageViews for different images? If I can change the picture
referenced how do I force a redraw? Is it possible to do this using the XML
layout to specify the Custom / Image / Surface View? Because the simpler
examples do this programaticaly.

Many thanks for your help,

Gav

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to