【问题标题】:Android image moving on button clickAndroid图像在按钮单击时移动
【发布时间】:2014-10-28 02:09:38
【问题描述】:

bee to android 编程和学习的东西。

我有以下代码,我需要的是在单击按钮时只移动两个选定的图像 第一个用户将选择两个图像 然后单击按钮,它们将向左移动

这是我的代码

 <ImageView
            android:id="@+id/imLady"
            android:layout_width="160dp"
            android:layout_height="238dp"
            android:src="@drawable/lady"
            android:layout_marginTop="50dp"/>


     <ImageView
        android:id="@+id/imLady2"
        android:layout_width="160dp"
        android:layout_height="238dp"
        android:src="@drawable/lady"
        android:layout_marginTop="50dp"/>

      <ImageView

        android:id="@+id/imLady3"
        android:layout_width="160dp"
        android:layout_height="238dp"
        android:src="@drawable/lady"
        android:layout_marginTop="50dp"/>


      <Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Move" />

期待你们的建议和解决方案:) 问候

【问题讨论】:

  • 那么到目前为止,您尝试了什么?您不能指望任何人只发布您的问题的完整解决方案。本网站仅用于帮助您了解如何自行获取它们或修复您可能遇到的任何错误。
  • Xaver 先生,这是我的错误,我没有输入我的活动代码,谢谢你告诉我这些事情

标签: android image button move


【解决方案1】:

您需要在 Button 的 onClick() 函数中为您的 ImageViews 设置动画

ImageView v1,v2;
 Button b;
TranslateAnimation ta1,ta2;
...
 public void onCreate(Bundle savedInstances)
 {
    super.onCreate(savedInstances);
    setContentView(R.layout.layoutname);
    ...
    initiate and refer button and imageviews
    ...
    ta1=new TranslateAnimation(fromx,tox,fromy,toy);
    ta1.setDuration(1000); //1 second

    ta2=new TranslateAnimation(fromx,tox,fromy,toy);
    ta2.setDuration(1000); //1 second

     b.setOnClickListener(new View.onClickListener(){
     @override
     public void onClick(View arg0)
     {
     v1.startAnimation(ta1);
     v2.startAnimation(ta2);
     }
     });


  }

参考翻译动画文档here

【讨论】:

  • 谢谢拉詹。我明白了,我知道如何移动图像,但我想要的是第一个用户应该选择两个图像,然后只有按钮 clcik 应该发生。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
  • 2013-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多