嗨,我是Android动画的新手.. 我希望在动画之后将我的图像更新到新的位置,但我没有这样做会感谢任何帮助..(我有一个从左到右,从右到左的基本动画)
XML -
<
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_menu_background"
android:orientation="vertical" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<View
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="60dp" >
<TextView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:background="@drawable/main_menu_fill"
android:padding="10dip"
android:text="My App"
android:textColor="@android:color/white"
android:textSize="34dp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<View
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<ImageView
android:id="@+id/btn1"
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill"
android:src="@drawable/main_menu_button" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<ImageView
android:id="@+id/btn2"
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill"
android:src="@drawable/main_menu_button" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<ImageView
android:id="@+id/btn3"
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill"
android:src="@drawable/main_menu_button" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<ImageView
android:id="@+id/btn4"
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill"
android:src="@drawable/main_menu_button" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<ImageView
android:id="@+id/btn5"
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill"
android:src="@drawable/main_menu_button" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:weightSum="4" >
<View
android:layout_width="0.5dip"
android:layout_weight="0.18"
android:background="@android:color/transparent" />
<View
android:layout_width="0.5dip"
android:layout_weight="0.65"
android:background="@drawable/main_menu_fill" />
<View
android:layout_width="3dip"
android:layout_weight="3.17"
android:background="@android:color/transparent" />
</TableRow>
</LinearLayout>
Java:
package com.example.mainmenuscreen;
import android.location.GpsStatus.Listener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
public class MainScreenActivity extends Activity {
OnClickListener openListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
Context context = getApplicationContext();
final ImageView login = (ImageView) findViewById(R.id.login);
final Animation lefttoright = AnimationUtils.loadAnimation(context,
R.anim.lefttoright);
Animation righttoleft = AnimationUtils.loadAnimation(context,
R.anim.righttoleft);
// login.startAnimation(righttoleft);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
login.startAnimation(lefttoright);
}
});
lefttoright.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
android.widget.LinearLayout.LayoutParams params = new LayoutParams(
android.widget.LinearLayout.LayoutParams.FILL_PARENT,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
// params.topMargin = login.getTop()-100;
params.setMargins(0, 0, 100, 0);
login.setLayoutParams(params);
}
});
}
}