2012-12-31 68 views
0

嗨,我是新來的Android動畫.. 我想更新我的形象後動畫,但我沒有這樣做會欣賞任何形式的幫助..(我有一個基本的左到右,從右到左的動畫)在動畫後設置imageview的新位置

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); 
      } 
     }); 
    } 
} 
+0

更好地使用RelativeLayout的,並調用login.requestLayout()後 – Tom

回答

1

你試過

Animation#setFillAfter 

API doc

+0

我改變了對動畫文件真實,似乎沒有工作... =( – crazyPixel

+0

沒錯,apperantly問題是在我的佈局,我將它從表格佈局更改爲線性佈局,並且做到了這一點 – crazyPixel