Button moves to different part of screen but can only press it at its initial spot?

丶灬走出姿态 提交于 2019-12-12 06:24:29

问题


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.


回答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.



来源:https://stackoverflow.com/questions/18550275/button-moves-to-different-part-of-screen-but-can-only-press-it-at-its-initial-sp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!