
我正在开发一个Android 2.2应用程序.
我想将图像从屏幕的左侧移动到屏幕的右侧.
我怎样才能做到这一点?我读过我必须将此图像添加到ListVIEw或GrIDVIEw来设置此动画.
UPDATE
我创建了以下文件:
动画/ translate_right
<?xml version="1.0" enCoding="utf-8"?><set xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:interpolator="@androID:anim/accelerate_decelerate_interpolator"> <translate androID:fromXDelta="-100%p" androID:toXDelta="0" androID:duration="5000" /></set>动画/ ship_layout_controller
<?xml version="1.0" enCoding="utf-8"?><layoutAnimation xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:delay="10%" androID:animationorder="reverse" androID:animation="@anim/translate_right" />布局/起始页
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:orIEntation="vertical"> <TextVIEw androID:ID="@+ID/appnameTextVIEw" androID:text="@string/app_name" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:layout_margintop="40px"/> <button androID:ID="@+ID/Playbutton" androID:text="@string/play" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:layout_margintop="40px"/> <absoluteLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" xmlns:androID="http://schemas.androID.com/apk/res/androID"> <ImageVIEw androID:ID="@+ID/greekShip" androID:persistentDrawingCache="animation|scrolling" androID:layoutAnimation="@anim/ship_layout_controller" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:src="@drawable/greekship" androID:maxWIDth="176px" androID:maxHeight="87px" androID:layout_x="-300px"/> </absoluteLayout></linearLayout>StartActivity.java
public class StartActivity extends Activity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.startpage); } @OverrIDe protected voID onResume() { super.onResume(); ImageVIEw ship = (ImageVIEw)findVIEwByID(R.ID.greekShip); ship.startAnimation(AnimationUtils.loadAnimation(this, R.anim.translate_right)); }}但这是行不通的.
解决方法:
请看一下Animation类,特别是Tween Animation,更特别是Translate element.在您的项目中创建一个动画文件,然后将该动画应用于图像.例如,此动画会将对象从屏幕中心移到右侧.
<?xml version="1.0" enCoding="utf-8"?><translate xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:toXDelta="100%p" androID:fromXDelta="0%" androID:duration="300" androID:fillEnabled="true" androID:fillAfter="true"></translate>编辑:将此动画应用于按钮,TextVIEw,ImageVIEw等.
ImageVIEw imageVIEw = (ImageVIEw) findVIEwByID(R.ID.myImageVIEw);Animation exitAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_animation);imageVIEw.startAnimation(exitAnimation); 总结 以上是内存溢出为你收集整理的android-通过linearlayout移动图像全部内容,希望文章能够帮你解决android-通过linearlayout移动图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)