[英]Translate Animation is not working perfectly in dynamic view
在此项目中,我想在单击按钮时将TextView的副本从顶部TextView位置移至底部TextView位置。
使用翻译动画时出现问题。 我想将视图移到确切位置(例如Zapya中的视图)。
在Zapya中,当用户选择项目并选择“发送”时, gridview项目的克隆将移至用户图标。 因此,我使用翻译动画来移动视图。 我动态创建了一个视图以显示项目的克隆。
使用“平移动画”可与最初在xml中创建的视图一起使用,但不适用于动态创建的视图。
代码在这里
top = (TextView) findViewById(R.id.textviewtop);
bottom = (TextView) findViewById(R.id.textviewbottom);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int []from = new int[2];
int []to = new int[2];
from[0] = (int) top.getX();
from[1] = (int) top.getY();
to[0] = (int) bottom.getX();
to[1] = (int) bottom.getY();
ViewGroup vg = (ViewGroup) top.getParent();
view = new TextView(getApplicationContext());
view.setWidth(top.getWidth());
view.setHeight(top.getHeight());
view.setX(from[0]);
view.setY(from[1]);
view.setText(top.getText());
view.setVisibility(View.VISIBLE);
view.setTextColor(Color.BLACK);
view.setId(0x23454657);
vg.addView(view);
TranslateAnimation anim = new TranslateAnimation( 0, 0 , from[1], to[1] );
anim.setDuration(1000);
anim.setFillAfter( true );
view.startAnimation(anim);
}
});
和xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textviewtop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:text="@string/hello_world" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Move"/>
<TextView
android:id="@+id/textviewbottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="@string/hello_world" />
</RelativeLayout>
“视图”仅显示开始和结束时间。 但不要介于两者之间。 我该如何解决。 请告知是否还有其他方法。 我会很感谢。
增加持续时间,可能是一个问题
anim.setDuration(4000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.