Animate *actual* position of a View

by Lance Fetters » Mon, 16 Nov 2009 12:47:20 GMT


Sponsored Links
 I am attempting to port a simple "tap the moving target" iPhone game
to Android (1.6). The game animates the position of a button, moving
it to random locations, while the user tries to tap it.

With the iPhone, moving the button is rather simple:

  [UIView beginAnimations:nil context:nil];
  button.center = CGPointMake(x, y);
  [UIView commitAnimations];


I have attempted to duplicate this on Android using Animation/
TranslateAnimation, but have found that this only affects where the
image of the button appears, not the tap boundaries. In other words,
even though the button appears to be moving, it is not possible to tap
it.

Is there a way to animate the actual position of a View in Android? If
not, does anyone have any suggestions on the "Android-way" of making
such a game?

--



Other Threads

1. -http-proxy option can't work in emulator with 1.5 sdk

D:\Downloads>emulator -avd avd15addon -sdcard d:\sd.iso -http-proxy
127.0.0.1:58
65 -debug-proxy
proxy_http_setup: creating http proxy service connecting to:
127.0.0.1:5865
server name '127.0.0.1' resolved to 127.0.0.1:5865
proxy_http_setup: creating HTTP Proxy Service Footer is (len=2):
'
'
http_service_connect: trying to connect to 64.233.189.104:80
http_service_connect: using HTTP rewriter
tcp:64.233.189.104:80(1480): cannot connect to proxy: <unknown error>
http_service_connect: trying to connect to 64.233.189.104:80
http_service_connect: using HTTP rewriter
tcp:64.233.189.104:80(1480): cannot connect to proxy: <unknown error>
http_service_connect: trying to connect to 64.233.189.104:80
http_service_connect: using HTTP rewriter
tcp:64.233.189.104:80(1480): cannot connect to proxy: <unknown error>
http_service_connect: trying to connect to 64.233.189.104:80
http_service_connect: using HTTP rewriter
tcp:64.233.189.104:80(1480): cannot connect to proxy: <unknown error>


--~--~---------~--~----~------------~-------~--~----~

2. Button in Custom View

I'm trying to create a button in a custom view that I've created. I'm
looping through an XML document and drawing certain things. I want to
be able to also create buttons to go in certain locations depending on
the xml data. I'd like to do it in the view because I want to be able
to call invalidate() on my view to redraw things and replace the
buttons when new xml data is available.

The problem is that I put my code in the view class, the activity
crashes because the button is "null". Here is a subset of my code:

Java:
     @Override
     protected void onDraw(Canvas canvas) {

          // Clock-size rectangle to draw compliance windows
          RectF clockRect = new RectF(86, 6, 394, 314);

          // Create a node list containing each reminder
          NodeList reminderNodes = this.clockXML.getElementsByTagName
("AdherenceInterval");
          int reminderLength = reminderNodes.getLength();

          Button checkbox = (Button) findViewById(R.id.checkbox);
        checkbox.setLayoutParams(new AbsoluteLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0, 0));
        checkbox.setOnClickListener(new Button.OnClickListener() {
          public void onClick(View v) {
               Context context = v.getContext();
               Intent i = new Intent(context,
ReportMedications.class);
               context.startActivity(i);
          }
        });



I know this code works for creating buttons because I can put it in my
activity class and it works just fine. Any suggestions? I thought
about relocating the button in the activity, but I can't figure out
how to do this when new data is available.
--~--~---------~--~----~------------~-------~--~----~

3. Fwd: Hello World Tutorial Error Message

4. Storm Trooper being arrested for carrying a loaded firearm view!

5. Issue in booting with new Android 1.5 (API level 3)

6. Issue in opening webpage in my application

7. scrolling in a dialog