0

Brief summary of my app: there are 2 buttons and a text view widget. Once the user clicks on the "Start" button, it will trigger a method in the that will shift the "main" button to another part of the screen. The text view will keep track of how many times the user clicks the "main" button.

My problem is that when the main button is shifted away, I can only register a button click when I press on the initial location of the main button

XML for the two buttons

<Button
        android:id="@+id/start_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/main_button"
        android:layout_alignBottom="@+id/main_button"
        android:layout_toLeftOf="@+id/click_number"
        android:text= "@string/start_button" 
        android:onClick="startClicked"
        />

    <Button
        android:id="@+id/main_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="30dp"
        android:onClick="buttonClicked"
        android:text="@string/button_text" />

Methods In the main:

  public void startClicked(View view){
      Button startButton = (Button)findViewById(R.id.start_button);
      startButton.setVisibility(View.GONE);
      move = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.move);
      findViewById(R.id.main_button).startAnimation(move);
        }

    public void buttonClicked(View view){

       TextView textView = (TextView)findViewById(R.id.click_number);
       textView.setText(" "+i);
        }

And Finally the move XML

<translate
        android:duration="800"
        android:fillAfter="true"
        android:fromXDelta="0%p"
        android:startOffset="300"
        android:toXDelta="10%p" />

</set>

Please let me know if you need more code or not. Thanks in advance.

Rohan
  • 1,312
  • 3
  • 17
  • 43

1 Answers1

1

This is expected. The original animation framework animates the pixels, not the touch zones of a widget.

The property animation framework -- including the NineOldAndroids backport -- moves the actual widget, including its touch zones.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • so in the startClicked method, would I do something like.... findViewById(R.id.main_button).animate().translationX(400).withLayer(); – Rohan Aug 31 '13 at 16:46