我想在Activity启动时创建简单的移动对象,但我无法找到解决方案。
我们说我有这个ImageView:
<ImageView
android:id="@+id/image_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/image"/>
这是我的测试活动:
public class TestActivity extends Activity {
ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
View view = super.onCreateView(name, context, attrs);
imageView = (ImageView) findViewById(R.id.image_view);
}
}
任何帮助将不胜感激。
答案 0 :(得分:0)
你必须使用动画:
ImageView img = (ImageView)findViewById(R.id.img);
TranslateAnimation ta = new TranslateAnimation(0,0,300,200);
ta.setDuration(5000);
img.startAnimation(ta);
http://developer.android.com/reference/android/view/animation/TranslateAnimation.html