无法与Android中的动画更改布局 [英] cannot change layout with animation in android

查看:136
本文介绍了无法与Android中的动画更改布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用改变布局 TranslateAnimation

我的XML是像

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直><按钮
    机器人:ID =@ + ID / buttonsld
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ ID / textsld
    机器人:文字=效果基本show/><的LinearLayout
    机器人:ID =@ + ID / layoutsld2
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_above =@ + ID / buttonsld2
    机器人:layout_below =@ + ID / buttonsld
    机器人:背景=@绘制/ IZ
    机器人:方向=垂直>
< / LinearLayout中><的LinearLayout
    机器人:ID =@ + ID / layoutsld3
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_above =@ + ID / buttonsld2
    机器人:layout_below =@ + ID / buttonsld
    机器人:背景=@绘制/自然之友
    机器人:方向=垂直
    机器人:知名度=水涨船高>
< / LinearLayout中><按钮
    机器人:ID =@ + ID / buttonsld2
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:文字=了slideDown/>< / RelativeLayout的>

和我的code是像

 私人INT X = 0;buttonslideup.setOnClickListener(新OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                如果(X == 0){
                    lin_lay2.setVisibility(View.GONE);
                    lin_lay3.setVisibility(View.VISIBLE);
                     动画滑动=新TranslateAnimation(0,0,100,0);
                     slide.setDuration(1000);
                     slide.setFillAfter(真);                     lin_lay3.startAnimation(幻灯片);
                    X = 1;
                }其他{
                    lin_lay3.setVisibility(View.GONE);                    lin_lay2.setVisibility(View.VISIBLE);
                     动画滑动=新TranslateAnimation(0,0,
                     100,0);                     slide.setDuration(1000);
                     slide.setFillAfter(真);
                     lin_lay2.startAnimation(幻灯片);
                    X = 0;
                }            }
        });

但是当我用这个,首先,在 lin_lay3 幻灯片,来筛选并没有问题,但是当我点击按钮再次, lin_lay2 幻灯片,但它的背后 lin_lay3 ,我无法看到 lin_lay2

我要的是改变这些布局点击按钮


解决方案

 启动按钮点击和放大器的另一个活动;看到乌尔活动布局的动画。
    只是把后starActivity(意向)这个code ..    overridePendingTransition(R.anim.slide_in_top,R.anim.slide_out_bottom);
    slide_in_top.xml
    < XML版本=1.0编码=UTF-8&GT?;
    <翻译的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:时间=@整数/ slideanim
        机器人:fromYDelta = - 100%P
        机器人:toYDelta =0/>    slide_out_bottom.xml
    < XML版本=1.0编码=UTF-8&GT?;
    <翻译的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:时间=@整数/ slideanim
        机器人:fromYDelta =0
        机器人:toYDelta =100%P/>    在价值文件夹中创建integer.xml&安培;放    <项目名称=slideanim格式=整数类型=整数> 1000℃; /项目>

I want to change layouts using TranslateAnimation.

My XML is like

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



<Button
    android:id="@+id/buttonsld"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/textsld"
    android:text="slideup" />

<LinearLayout
    android:id="@+id/layoutsld2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/buttonsld2"
    android:layout_below="@+id/buttonsld"
    android:background="@drawable/iz"
    android:orientation="vertical" >
</LinearLayout>

<LinearLayout
    android:id="@+id/layoutsld3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/buttonsld2"
    android:layout_below="@+id/buttonsld"
    android:background="@drawable/fon"
    android:orientation="vertical"
    android:visibility="gone" >
</LinearLayout>

<Button
    android:id="@+id/buttonsld2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="slidedown" />

</RelativeLayout>

and my code is like

 private int x= 0;

buttonslideup.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (x == 0) {
                    lin_lay2.setVisibility(View.GONE);
                    lin_lay3.setVisibility(View.VISIBLE);
                     Animation slide = new TranslateAnimation(0, 0, 100, 0);
                     slide.setDuration(1000);
                     slide.setFillAfter(true);

                     lin_lay3.startAnimation(slide);
                    x = 1;
                } else {
                    lin_lay3.setVisibility(View.GONE);

                    lin_lay2.setVisibility(View.VISIBLE);
                     Animation slide = new TranslateAnimation(0, 0,
                     100, 0);

                     slide.setDuration(1000);
                     slide.setFillAfter(true);
                     lin_lay2.startAnimation(slide);
                    x = 0;
                }

            }
        });

but when I use this, at first, the lin_lay3 slides and comes to screen and there is no problem, but when I click to button again, lin_lay2 slides, but it is behind lin_lay3 and I cannot see lin_lay2.

What I want is to change these layouts with the click of the button.

解决方案

 you start another activity on button click & see the animation of ur activity layout.
    just put this code after starActivity(intent)..

    overridePendingTransition(R.anim.slide_in_top, R.anim.slide_out_bottom);


    slide_in_top.xml
    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@integer/slideanim"
        android:fromYDelta="-100%p"
        android:toYDelta="0" />

    slide_out_bottom.xml
    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@integer/slideanim"
        android:fromYDelta="0"
        android:toYDelta="100%p" />

    in value folder create integer.xml & put

    <item name="slideanim" format="integer" type="integer">1000</item>

这篇关于无法与Android中的动画更改布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆