按钮移动到屏幕的不同部分,但只能preSS它在它的初始位置? [英] Button moves to different part of screen but can only press it at its initial spot?

查看:160
本文介绍了按钮移动到屏幕的不同部分,但只能preSS它在它的初始位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序小结:有2个按钮和一个文本视图控件。一旦用户点击了开始按钮时,会触发在一个方法,将主钮移位到屏幕的另一部分。文本视图将跟踪用户多少次点击主按钮。

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.

我的问题是,当主按钮被转移走,我只能注册点击一个按钮,当我的主按钮的初始位置preSS

的XML为两个按钮

<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" />

方法在主:

  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);
        }

和最后的举动XML

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

</set>

请让我知道如果你需要更多的code与否。
提前致谢。

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

推荐答案

这是预期。原来的动画框架的动画的像素的,而不是一个小部件的触摸区。

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

借助属性动画框架 - 包括的的NineOldAndroids的backport - 移动部件的实际,包括它的触控区

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

这篇关于按钮移动到屏幕的不同部分,但只能preSS它在它的初始位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆