Android的使用转换动画的图像视图点击我的动画相对布局从下到上,从上到下我的、动画、视图、布局

2023-09-13 00:41:43 作者:劫后余生

我需要让我的动画相对布局时,点击图像视图。

1.Moving相对布局从底部到顶部(点击他的图像视图时)。

2.Moving从顶部回到底部(在图像视图中再次点击他的时候)。

首先,当我点击图片查看它的正常工作和相对布局从下向上顶,但是当我再次点击图片查看它的动画从上到下,当它达到了原来的位置,这是隐藏在我的活动..any帮助,在此先感谢。

这是我的活动:

 公共类MainActivity延伸活动{

RelativeLayout的rl_footer;
ImageView的iv_header;
布尔isBottom = TRUE;
按钮BTN1;

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    rl_footer =(RelativeLayout的)findViewById(R.id.rl_footer);
    iv_header =(ImageView的)findViewById(R.id.iv_up_arrow);
    iv_header.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            iv_header.setImageResource(R.drawable.down_arrow);
            // iv_header.setVisibility(View.INVISIBLE);
            // iv_down.setVisibility(View.VISIBLE);
            iv_header.setPadding(0,10,0,0); //替代参数
                                                //左,上,右,下
            rl_footer.setBackgroundResource(R.drawable.up_manu_bar);
            // FooterAnimation();

            如果(isBottom){
                FooterAnimation();
                isBottom = FALSE;
            } 其他 {
                iv_header.setImageResource(R.drawable.up_arrow);
                iv_header.setPadding(0,0,0,10);
                rl_footer.setBackgroundResource(R.drawable.down_manu_bar1);
                headerAnimation();
                isBottom = TRUE;
            }

        }
    });

}

公共无效FooterAnimation(){
    动画幻灯片= NULL;
    滑动=新TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0,
            Animation.RELATIVE_TO_SELF,0.0,Animation.RELATIVE_TO_SELF,
            0.0,Animation.RELATIVE_TO_SELF,-5.0f);

    slide.setDuration(400);
    slide.setFillAfter(真正的);
    slide.setFillEnabled(真正的);
    rl_footer.startAnimation(幻灯片);

    slide.setAnimationListener(新AnimationListener(){

        @覆盖
        公共无效onAnimationStart(动画动画){

        }

        @覆盖
        公共无效onAnimationRepeat(动画动画){
        }

        @覆盖
        公共无效onAnimationEnd(动画动画){

            rl_footer.clearAnimation();

            如果(isBottom){
                RelativeLayout.LayoutParams LP =新RelativeLayout.LayoutParams(
                        rl_footer.getWidth(),rl_footer.getHeight());
                lp.setMargins(rl_footer.getWidth(),0,0,0);
                rl_footer.setLayoutParams(LP);
            } 其他 {
                RelativeLayout.LayoutParams LP =新RelativeLayout.LayoutParams(
                        rl_footer.getWidth(),rl_footer.getHeight());
                lp.setMargins(0,0,0,0);
                rl_footer.setLayoutParams(LP);
            }

        }

    });

}

公共无效headerAnimation(){

    动画幻灯片= NULL;
    滑动=新TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0,
            Animation.RELATIVE_TO_SELF,0.0,Animation.RELATIVE_TO_SELF,
            0.0,Animation.RELATIVE_TO_SELF,5.2f);

    slide.setDuration(400);
    slide.setFillAfter(真正的);
    slide.setFillEnabled(真正的);
    rl_footer.startAnimation(幻灯片);

    slide.setAnimationListener(新AnimationListener(){

        @覆盖
        公共无效onAnimationStart(动画动画){

        }

        @覆盖
        公共无效onAnimationRepeat(动画动画){
        }

        @覆盖
        公共无效onAnimationEnd(动画动画){

            rl_footer.clearAnimation();

            如果(isBottom){
                RelativeLayout.LayoutParams LP =新RelativeLayout.LayoutParams(
                        rl_footer.getWidth(),rl_footer.getHeight());
                lp.setMargins(rl_footer.getWidth(),0,0,0);
                rl_footer.setLayoutParams(LP);
            } 其他 {
                RelativeLayout.LayoutParams LP =新RelativeLayout.LayoutParams(
                        rl_footer.getWidth(),rl_footer.getHeight());
                lp.setMargins(0,0,0,0);
                rl_footer.setLayoutParams(LP);
            }

        }

    });

}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    //充气菜单;这增加了项目操作栏,如果它是present。
    。getMenuInflater()膨胀(R.menu.main,菜单);
    返回true;
}

 }
 

和我的XML:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID / rl_main
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@可绘制/ autograph_bg>

< RelativeLayout的
    机器人:ID =@ + ID / rl_footer
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =70dp
    机器人:layout_alignParentBottom =真
    机器人:背景=@可绘制/ down_manu_bar1>

    < ImageView的
        机器人:ID =@ + ID / iv_new_file
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignParentLeft =真
        机器人:layout_centerVertical =真
        机器人:layout_marginLeft =18dp
        机器人:的onClick =onNewFileClick
        机器人:SRC =@可绘制/ file_icon/>

    <的TextView
        机器人:ID =@ + ID / tv_new_file
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / iv_new_file
        机器人:layout_below =@ + ID / iv_new_file
        机器人:文本=新
        机器人:文字颜色=#FFFFFF/>

    < ImageView的
        机器人:ID =@ + ID / iv_insert
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignTop =@ + ID / iv_new_file
        机器人:layout_marginLeft =30dp
        机器人:layout_toRightOf =@ + ID / iv_new_file
        机器人:SRC =@可绘制/ insert_icon/>

    <的TextView
        机器人:ID =@ + ID / tv_insert
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / iv_insert
        机器人:layout_below =@ + ID / iv_insert
        机器人:文本=插入
        机器人:文字颜色=#FFFFFF/>

    < ImageView的
        机器人:ID =@ + ID / iv_up_arrow
        机器人:layout_width =45dp
        机器人:layout_height =45dp
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:paddingBottom会=10dp
        机器人:SRC =@可绘制/ up_arrow/>

    < ImageView的
        机器人:ID =@ + ID / iv_down_arrow
        机器人:layout_width =45dp
        机器人:layout_height =45dp
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:背景=@可绘制/ down_arrow
        机器人:paddingBottom会=10dp
        机器人:能见度=水涨船高/>

    < ImageView的
        机器人:ID =@ + ID / iv_save
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignTop =@ + ID / iv_insert
        机器人:layout_marginLeft =30dp
        机器人:layout_toRightOf =@ + ID / iv_up_arrow
        机器人:SRC =@可绘制/保存/>

    <的TextView
        机器人:ID =@ + ID / tv_save
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / iv_save
        机器人:layout_alignParentBottom =真
        机器人:文本=保存
        机器人:文字颜色=#FFFFFF/>

    < ImageView的
        机器人:ID =@ + ID / iv_settings
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignTop =@ + ID / iv_save
        机器人:layout_marginLeft =27dp
        机器人:layout_toRightOf =@ + ID / tv_save
        机器人:paddingTop =2DP
        机器人:SRC =@可绘制/ icon_settings/>

    <的TextView
        机器人:ID =@ + ID / tv_settings
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_marginLeft =260dp
        机器人:文本=设置
        机器人:文字颜色=#FFFFFF/>
 < / RelativeLayout的>

< / RelativeLayout的>
 
这四种如丝滑般的幻灯片切换效果,就是这么柔顺

解决方案

我已经解决了我的问题,现在我的动画正常工作:) 如果有人需要的只是复制我的code和XML和PLZ不感谢:P

我的动态MainActivity:

 进口android.os.Bundle;
进口android.app.Activity;
进口android.content.Intent;
进口android.view.Menu;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.view.animation.Animation;
进口android.view.animation.Animation.AnimationListener;
进口android.view.animation.AnimationUtils;
进口android.view.animation.TranslateAnimation;
进口android.widget.Button;
进口android.widget.ImageView;
进口android.widget.RelativeLayout;

公共类MainActivity延伸活动{

RelativeLayout的rl_footer;
ImageView的iv_header;
布尔isBottom = TRUE;
按钮BTN1;

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    rl_footer =(RelativeLayout的)findViewById(R.id.rl_footer);
    iv_header =(ImageView的)findViewById(R.id.iv_up_arrow);
    iv_header.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            iv_header.setImageResource(R.drawable.down_arrow);
            iv_header.setPadding(0,10,0,0);
            rl_footer.setBackgroundResource(R.drawable.up_manu_bar);
            如果(isBottom){
                SlideToAbove();
                isBottom = FALSE;
            } 其他 {
                iv_header.setImageResource(R.drawable.up_arrow);
                iv_header.setPadding(0,0,0,10);
                rl_footer.setBackgroundResource(R.drawable.down_manu_bar1);
                SlideToDown();
                isBottom = TRUE;
            }

        }
    });

}

公共无效SlideToAbove(){
    动画幻灯片= NULL;
    滑动=新TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0,
            Animation.RELATIVE_TO_SELF,0.0,Animation.RELATIVE_TO_SELF,
            0.0,Animation.RELATIVE_TO_SELF,-5.0f);

    slide.setDuration(400);
    slide.setFillAfter(真正的);
    slide.setFillEnabled(真正的);
    rl_footer.startAnimation(幻灯片);

    slide.setAnimationListener(新AnimationListener(){

        @覆盖
        公共无效onAnimationStart(动画动画){

        }

        @覆盖
        公共无效onAnimationRepeat(动画动画){
        }

        @覆盖
        公共无效onAnimationEnd(动画动画){

            rl_footer.clearAnimation();

            RelativeLayout.LayoutParams LP =新RelativeLayout.LayoutParams(
                    rl_footer.getWidth(),rl_footer.getHeight());
            // lp.setMargins(0,0,0,0);
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            rl_footer.setLayoutParams(LP);

        }

    });

}

公共无效SlideToDown(){
    动画幻灯片= NULL;
    滑动=新TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0,
            Animation.RELATIVE_TO_SELF,0.0,Animation.RELATIVE_TO_SELF,
            0.0,Animation.RELATIVE_TO_SELF,5.2f);

    slide.setDuration(400);
    slide.setFillAfter(真正的);
    slide.setFillEnabled(真正的);
    rl_footer.startAnimation(幻灯片);

    slide.setAnimationListener(新AnimationListener(){

        @覆盖
        公共无效onAnimationStart(动画动画){

        }

        @覆盖
        公共无效onAnimationRepeat(动画动画){
        }

        @覆盖
        公共无效onAnimationEnd(动画动画){

            rl_footer.clearAnimation();

            RelativeLayout.LayoutParams LP =新RelativeLayout.LayoutParams(
                    rl_footer.getWidth(),rl_footer.getHeight());
            lp.setMargins(0,rl_footer.getWidth(),0,0);
            lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            rl_footer.setLayoutParams(LP);

        }

    });

}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    //充气菜单;这增加了项目操作栏,如果它是present。
    。getMenuInflater()膨胀(R.menu.main,菜单);
    返回true;
}

 }
 

和我的XML activity_main:

 < XML版本=1.0编码=UTF-8&GT?;
 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:ID =@ + ID / rl_main
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  机器人:背景=@可绘制/ autograph_bg>

 < RelativeLayout的
    机器人:ID =@ + ID / rl_footer
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =70dp
    机器人:layout_alignParentBottom =真
    机器人:背景=@可绘制/ down_manu_bar1>

    < ImageView的
        机器人:ID =@ + ID / iv_new_file
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignParentLeft =真
        机器人:layout_centerVertical =真
        机器人:layout_marginLeft =18dp
        机器人:的onClick =onNewFileClick
        机器人:SRC =@可绘制/ file_icon/>

    <的TextView
        机器人:ID =@ + ID / tv_new_file
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / iv_new_file
        机器人:layout_below =@ + ID / iv_new_file
        机器人:文本=新
        机器人:文字颜色=#FFFFFF/>

    < ImageView的
        机器人:ID =@ + ID / iv_insert
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignTop =@ + ID / iv_new_file
        机器人:layout_marginLeft =30dp
        机器人:layout_toRightOf =@ + ID / iv_new_file
        机器人:SRC =@可绘制/ insert_icon/>

    <的TextView
        机器人:ID =@ + ID / tv_insert
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / iv_insert
        机器人:layout_below =@ + ID / iv_insert
        机器人:文本=插入
        机器人:文字颜色=#FFFFFF/>

    < ImageView的
        机器人:ID =@ + ID / iv_up_arrow
        机器人:layout_width =45dp
        机器人:layout_height =45dp
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:paddingBottom会=10dp
        机器人:SRC =@可绘制/ up_arrow/>

    < ImageView的
        机器人:ID =@ + ID / iv_down_arrow
        机器人:layout_width =45dp
        机器人:layout_height =45dp
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:背景=@可绘制/ down_arrow
        机器人:paddingBottom会=10dp
        机器人:能见度=水涨船高/>

    < ImageView的
        机器人:ID =@ + ID / iv_save
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignTop =@ + ID / iv_insert
        机器人:layout_marginLeft =30dp
        机器人:layout_toRightOf =@ + ID / iv_up_arrow
        机器人:SRC =@可绘制/保存/>

    <的TextView
        机器人:ID =@ + ID / tv_save
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / iv_save
        机器人:layout_alignParentBottom =真
        机器人:文本=保存
        机器人:文字颜色=#FFFFFF/>

    < ImageView的
        机器人:ID =@ + ID / iv_settings
        机器人:layout_width =25dp
        机器人:layout_height =25dp
        机器人:layout_alignTop =@ + ID / iv_save
        机器人:layout_marginLeft =27dp
        机器人:layout_toRightOf =@ + ID / tv_save
        机器人:paddingTop =2DP
        机器人:SRC =@可绘制/ icon_settings/>

    <的TextView
        机器人:ID =@ + ID / tv_settings
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_marginLeft =260dp
        机器人:文本=设置
        机器人:文字颜色=#FFFFFF/>
 < / RelativeLayout的>

 < / RelativeLayout的>
 

只是创建新的Andr​​oid项目,并复制粘贴我的code和乐趣! :) 还记得在XML我有图像显示和他的背景图片更换YOUT自己的图片感谢..

I Need to make animate my Relative Layout when click on image view..

1.Moving Relative Layout from Bottom to Top (when clicking him on image view).

2.Moving back from Top to Bottom (when clicking him again on image view).

First when i click on image view it's works fine and Relative Layout move up from bottom to top, but when i click again on image view it's animate from top to bottom, when it's reached to the original position it's hide on my activity..any help and Thanks in advance.

This is my Activity :

 public class MainActivity extends Activity {

RelativeLayout rl_footer;
ImageView iv_header;
boolean isBottom = true;
Button btn1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    rl_footer = (RelativeLayout) findViewById(R.id.rl_footer);
    iv_header = (ImageView) findViewById(R.id.iv_up_arrow);
    iv_header.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            iv_header.setImageResource(R.drawable.down_arrow);
            // iv_header.setVisibility(View.INVISIBLE);
            // iv_down.setVisibility(View.VISIBLE);
            iv_header.setPadding(0, 10, 0, 0); // substitute parameters for
                                                // left, top, right, bottom
            rl_footer.setBackgroundResource(R.drawable.up_manu_bar);
            // FooterAnimation();

            if (isBottom) {
                FooterAnimation();
                isBottom = false;
            } else {
                iv_header.setImageResource(R.drawable.up_arrow);
                iv_header.setPadding(0, 0, 0, 10);
                rl_footer.setBackgroundResource(R.drawable.down_manu_bar1);
                headerAnimation();
                isBottom = true;
            }

        }
    });

}

public void FooterAnimation() {
    Animation slide = null;
    slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, -5.0f);

    slide.setDuration(400);
    slide.setFillAfter(true);
    slide.setFillEnabled(true);
    rl_footer.startAnimation(slide);

    slide.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            rl_footer.clearAnimation();

            if (isBottom) {
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        rl_footer.getWidth(), rl_footer.getHeight());
                lp.setMargins(rl_footer.getWidth(), 0, 0, 0);
                rl_footer.setLayoutParams(lp);
            } else {
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        rl_footer.getWidth(), rl_footer.getHeight());
                lp.setMargins(0, 0, 0, 0);
                rl_footer.setLayoutParams(lp);
            }

        }

    });

}

public void headerAnimation() {

    Animation slide = null;
    slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 5.2f);

    slide.setDuration(400);
    slide.setFillAfter(true);
    slide.setFillEnabled(true);
    rl_footer.startAnimation(slide);

    slide.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            rl_footer.clearAnimation();

            if (isBottom) {
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        rl_footer.getWidth(), rl_footer.getHeight());
                lp.setMargins(rl_footer.getWidth(), 0, 0, 0);
                rl_footer.setLayoutParams(lp);
            } else {
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        rl_footer.getWidth(), rl_footer.getHeight());
                lp.setMargins(0, 0, 0, 0);
                rl_footer.setLayoutParams(lp);
            }

        }

    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

 }

and my Xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/autograph_bg" >

<RelativeLayout
    android:id="@+id/rl_footer"
    android:layout_width="fill_parent"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/down_manu_bar1" >

    <ImageView
        android:id="@+id/iv_new_file"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="18dp"
        android:onClick="onNewFileClick"
        android:src="@drawable/file_icon" />

    <TextView
        android:id="@+id/tv_new_file"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_new_file"
        android:layout_below="@+id/iv_new_file"
        android:text="New"
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/iv_insert"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignTop="@+id/iv_new_file"
        android:layout_marginLeft="30dp"
        android:layout_toRightOf="@+id/iv_new_file"
        android:src="@drawable/insert_icon" />

    <TextView
        android:id="@+id/tv_insert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_insert"
        android:layout_below="@+id/iv_insert"
        android:text="Insert"
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/iv_up_arrow"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:paddingBottom="10dp"
        android:src="@drawable/up_arrow" />

    <ImageView
        android:id="@+id/iv_down_arrow"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/down_arrow"
        android:paddingBottom="10dp"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/iv_save"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignTop="@+id/iv_insert"
        android:layout_marginLeft="30dp"
        android:layout_toRightOf="@+id/iv_up_arrow"
        android:src="@drawable/save" />

    <TextView
        android:id="@+id/tv_save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_save"
        android:layout_alignParentBottom="true"
        android:text="Save"
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/iv_settings"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignTop="@+id/iv_save"
        android:layout_marginLeft="27dp"
        android:layout_toRightOf="@+id/tv_save"
        android:paddingTop="2dp"
        android:src="@drawable/icon_settings" />

    <TextView
        android:id="@+id/tv_settings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="260dp"
        android:text="Settings"
        android:textColor="#ffffff" />
 </RelativeLayout>

</RelativeLayout>

解决方案

I have solved my issue and now my animation works fine :) if anyone needed just copy my code and xml and plz don't thanks :p

My Activity MainActivity:

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class MainActivity extends Activity {

RelativeLayout rl_footer;
ImageView iv_header;
boolean isBottom = true;
Button btn1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    rl_footer = (RelativeLayout) findViewById(R.id.rl_footer);
    iv_header = (ImageView) findViewById(R.id.iv_up_arrow);
    iv_header.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            iv_header.setImageResource(R.drawable.down_arrow);
            iv_header.setPadding(0, 10, 0, 0); 
            rl_footer.setBackgroundResource(R.drawable.up_manu_bar);
            if (isBottom) {
                SlideToAbove();
                isBottom = false;
            } else {
                iv_header.setImageResource(R.drawable.up_arrow);
                iv_header.setPadding(0, 0, 0, 10);
                rl_footer.setBackgroundResource(R.drawable.down_manu_bar1);
                SlideToDown();
                isBottom = true;
            }

        }
    });

}

public void SlideToAbove() {
    Animation slide = null;
    slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, -5.0f);

    slide.setDuration(400);
    slide.setFillAfter(true);
    slide.setFillEnabled(true);
    rl_footer.startAnimation(slide);

    slide.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            rl_footer.clearAnimation();

            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    rl_footer.getWidth(), rl_footer.getHeight());
            // lp.setMargins(0, 0, 0, 0);
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            rl_footer.setLayoutParams(lp);

        }

    });

}

public void SlideToDown() {
    Animation slide = null;
    slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 5.2f);

    slide.setDuration(400);
    slide.setFillAfter(true);
    slide.setFillEnabled(true);
    rl_footer.startAnimation(slide);

    slide.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            rl_footer.clearAnimation();

            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    rl_footer.getWidth(), rl_footer.getHeight());
            lp.setMargins(0, rl_footer.getWidth(), 0, 0);
            lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            rl_footer.setLayoutParams(lp);

        }

    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

 }

and my Xml activity_main:

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/rl_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/autograph_bg" >

 <RelativeLayout
    android:id="@+id/rl_footer"
    android:layout_width="fill_parent"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/down_manu_bar1" >

    <ImageView
        android:id="@+id/iv_new_file"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="18dp"
        android:onClick="onNewFileClick"
        android:src="@drawable/file_icon" />

    <TextView
        android:id="@+id/tv_new_file"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_new_file"
        android:layout_below="@+id/iv_new_file"
        android:text="New"
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/iv_insert"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignTop="@+id/iv_new_file"
        android:layout_marginLeft="30dp"
        android:layout_toRightOf="@+id/iv_new_file"
        android:src="@drawable/insert_icon" />

    <TextView
        android:id="@+id/tv_insert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_insert"
        android:layout_below="@+id/iv_insert"
        android:text="Insert"
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/iv_up_arrow"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:paddingBottom="10dp"
        android:src="@drawable/up_arrow" />

    <ImageView
        android:id="@+id/iv_down_arrow"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/down_arrow"
        android:paddingBottom="10dp"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/iv_save"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignTop="@+id/iv_insert"
        android:layout_marginLeft="30dp"
        android:layout_toRightOf="@+id/iv_up_arrow"
        android:src="@drawable/save" />

    <TextView
        android:id="@+id/tv_save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_save"
        android:layout_alignParentBottom="true"
        android:text="Save"
        android:textColor="#ffffff" />

    <ImageView
        android:id="@+id/iv_settings"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignTop="@+id/iv_save"
        android:layout_marginLeft="27dp"
        android:layout_toRightOf="@+id/tv_save"
        android:paddingTop="2dp"
        android:src="@drawable/icon_settings" />

    <TextView
        android:id="@+id/tv_settings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="260dp"
        android:text="Settings"
        android:textColor="#ffffff" />
 </RelativeLayout>

 </RelativeLayout>

just create new android project and copy paste my code and have fun! :) also remember in xml i have image view and his background images replace with yout own images thanks..

 
精彩推荐