Hello,
I'm trying to initiate an animation to run in a specific xml-defined
view with a button push. Currently It runs when I push the button but
but the animation uses the entire display, covering all of the other
widgets including the button used to start it.
The info and examples I've found all demmonstrate how to display
animation in the full screen upon startup of the layout activity. My
goal is to initiate animation in an xml-defined surface view that
resides INSIDE the layout.
On other platforms I would simply create a timer (initiated and/or
terminated by the button push) in the ui thread which does the
animation in slices. Is there any concept like that in android?
Anyways, in the onClick method I get the surface view using the id
specified in the xml. I then create my surface view object and pass
the context of the surface view. Alas, this doesn't work.
Here's a sub-layout section of my XML code (tabBattle.xml).
<LinearLayout
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:id="@+id/battleView"
android:layout_weight="70"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<Button
android:onClick="onClick"
android:text=" Go "
android:gravity="center"
android:layout_weight="30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Here's my main activity class. This is created when I navigate to the
tab view where its layout (tabBattle) resides. The onClick is called
when I push the Go button. My intention in onClick is to get the
surface view, create a new BattleView instance, and and pass the
surface view context to the BattleView constructor. This clearly is
not correct but I have no idea how else to accomplish my goal.
public class BattleActivity extends Activity implements
View.OnClickListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tabbattle);
}
@Override
public void onClick(View v)
{
SurfaceView battleSurface =
(SurfaceView)findViewById(R.id.battleView);
setContentView(new BattleView( battleSurface.getContext() ));
}
}
SurfaceView subclass:
public class BattleView extends SurfaceView implements
SurfaceHolder.Callback
{
private int circleRadius;
private Paint circlePaint;
UpdateThreadBattle updateThread;
private int width;
private int height;
private int xPos;
private int yPos;
private int xVel;
private int yVel;
public BattleView(Context context)
{
super(context);
getHolder().addCallback(this);
circleRadius = 10;
circlePaint = new Paint();
circlePaint.setColor(Color.BLUE);
xVel = 2;
yVel = 2;
}
@Override
protected void onDraw(Canvas canvas) {
// you can always experiment by removing this line if you wish!
canvas.drawColor(Color.WHITE);
canvas.drawCircle(xPos, yPos, circleRadius, circlePaint);
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
Rect surfaceFrame = holder.getSurfaceFrame();
width = surfaceFrame.width();
height = surfaceFrame.height();
xPos = width / 2;
yPos = circleRadius;
updateThread = new UpdateThreadBattle(this);
updateThread.setRunning(true);
updateThread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0)
{
boolean retry = true;
updateThread.setRunning(false);
while (retry) {
try {
updateThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
}
I would appreciate ANY help here. Thanks!
Greg
--
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