如何将ImageView移动到另一个ImageView Android动画

问题描述:

任何人都知道我可以如何将imageview移动到另一个imageview?如何将ImageView移动到另一个ImageView Android动画

enter image description here

IM在这种方法中,又或许想是另外一个,我不知道......没问题,我很高兴去学习它

<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillAfter="true" 
android:interpolator="@android:anim/linear_interpolator"> 

<translate 
    android:duration="800" 
    android:fromXDelta="0%p" 
    android:toXDelta="75%p" /> 

我知道来自XDelta(是起始位置),toXDelta是应该到达的位置..但是?我怎么能知道我的起始位置和到达位置看我的图片示例?

添加细节:

有4点不同的布局在这里,但只有3个是与权重值。 从顶部的酒吧是按钮是一个布局,但没有像其余的重量。

多达所以铺设卡在布局1 我想要的位置到达是从上下布局2 扑克牌在layout3

而且我在使用XML的onClick方法不onClickListeners。由于

您可以通过编程做到这一点是这样的:

@Override protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    final View target = findViewById(R.id.target); 
    final View viewToMove = findViewById(R.id.viewToMove); 

    viewToMove.setOnClickListener(new View.OnClickListener() { 
     @Override public void onClick(View v) { 
      translate(viewToMove, target); 
     } 
    }); 
} 

private void translate(View viewToMove, View target) { 
    viewToMove.animate() 
      .x(target.getX()) 
      .y(target.getY()) 
      .setDuration(1000) 
      .start(); 
} 

这里的XML:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
android:id="@+id/activity_main" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ImageView 
    android:id="@+id/target" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_gravity="center" 
    android:background="@color/colorAccent"/> 

<ImageView 
    android:id="@+id/viewToMove" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:background="@color/colorPrimary" 
    android:src="@mipmap/ic_launcher"/> 
</FrameLayout> 
+0

感谢您的回答,但...这方法是不工作...我需要第一纸牌移动到的ImageView其中箭头结束。 在我的应用程序中使用像这样实现的代码之后: ImageView poz1Inamic =(ImageView)findViewById(R.id.inamic_pozitia1); ImageView cartePusaInamic =(ImageView)findViewById(R.id.cartePusaInamic); poz1Inamic.animate() .X(cartePusaInamic.getX()) .Y(cartePusaInamic.getY()) .setDuration(1000) 。开始(); imageview不要去我想要的视图 –

+0

请添加更多关于您的视图层次结构的细节。 isamic_pozitia1和cartePusaInamic是否在相同的布局? –

+0

添加了请求的详细信息 –

Finnaly我有用户的帮助succeded弗朗索瓦·L.

被很多的工作要做,我不会说不,因为我需要重新设计我所有的布局,但这不是问题,因为我学到了一些新的东西,并且我非常感谢所有可以获得的帮助。

如果有人想将视图(任何类型的视图,图像视图,按钮视图,文本视图等)移动到另一个视图,则必须使两个视图处于相同的布局中,这是最重要的部分。

和代码实现这一目标是:

//here is the part of initialization 
    ImageView poz1Inamic = (ImageView) findViewById(inamic_pozitia1); 
    ImageView poz1InamicSpateCarte = (ImageView) findViewById(inamic_pozitia1spatecarte); 

    //other code 
    poz1InamicSpateCarte.setVisibility(View.INVISIBLE); 

    //here is the initialization of the arrive position 
    ImageView cartePusaInamic = (ImageView) findViewById(R.id.cartePusaInamic); 

    //the code for moving from start position to arrive position 
    poz1Inamic.animate() 
      .x(cartePusaInamic.getX()) 
      .y(cartePusaInamic.getY()) 
      .setDuration(333) 
      .start();