Android的使用动画的LinearLayout增长 [英] Android grow LinearLayout using animation

查看:209
本文介绍了Android的使用动画的LinearLayout增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用动画制作的布局出现在屏幕上。这个想法是,布局将开始为0的高度和长到100%。

I am trying to use animation to make a layout appear on screen. The idea is that layout will start with height of 0 and grow to 100%.

我有这个真正的麻烦,需要一些帮助。出于某种原因,不进行任何的动画。

I have real troubles with this and need some assistance. For some reason no animation is performed.

下面是我的动画XML文件

Here is my animation XML file

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="0.0"
        android:toXScale="1"
        android:fromYScale="1.0"
        android:toYScale="1.0"
        android:fillAfter="false"
         />

</set>

布局文件是很基本的,被设计成以下

The layout file is very basic and is designed as following

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
        android:id="@+id/dialog"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_centerHorizontal="true"
        android:orientation="vertical"
        android:layout_centerVertical="true"
        android:background="@drawable/border">
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Phone"
            android:id="@+id/textView"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Address"
            android:id="@+id/textView1"/>
    <Button android:id="@+id/btn1"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="Action 1"
            />
    <Button android:id="@+id/btn2"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="Action 2"
            />
</LinearLayout>
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Animate"
        android:id="@+id/btnAnimate" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
        android:onClick="animate"/>
</RelativeLayout>

我的活动code是很基本的,以及

My activity code is very basic as well

public class MyActivity extends Activity implements Animation.AnimationListener{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
 }

public void animate(View view){
    LinearLayout dialog   = (LinearLayout)findViewById(R.id.dialog);
    dialog.setVisibility(LinearLayout.VISIBLE);
    Animation animation   =    AnimationUtils.loadAnimation(this, R.anim.anim);
    Log.i("animate","Begin Animation");
    animation.reset();
  //  animation.setFillAfter(true);
    animation.setAnimationListener(this);
    dialog.setAnimation(null);
    Log.i("animate","End Animation");
}

@Override
public void onAnimationStart(Animation animation) {
    //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public void onAnimationEnd(Animation animation) {
    //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public void onAnimationRepeat(Animation animation) {
    //To change body of implemented methods use File | Settings | File Templates.
}
}

感谢您

推荐答案

好吧,我想它了。

动画XML布局

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:fillEnabled="true"
 android:fillAfter="true">
 <scale

        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="1.0"
        android:fromYScale="0.0"
        android:toYScale="1.0"
        android:fillAfter="false"
         />

</set>

布局XML文件

Layout XML file

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">

  <LinearLayout
        android:id="@+id/dialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="vertical"
        android:layout_centerVertical="true"
        android:visibility="invisible"
        android:background="@drawable/border">
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Phone"
            android:id="@+id/textView"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Address"
            android:id="@+id/textView1"/>
    <Button android:id="@+id/btn1"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="Action 1"
            />
    <Button android:id="@+id/btn2"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="Action 2"
            />
   </LinearLayout>
   <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Animate"
        android:id="@+id/btnAnimate" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
        android:onClick="animate"/>
</RelativeLayout>

和我的Activity类

and my Activity class

public class MyActivity extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
 }

public void animate(View view){
    LinearLayout dialog   = (LinearLayout)findViewById(R.id.dialog);
    dialog.setVisibility(LinearLayout.VISIBLE);
    Animation animation   =    AnimationUtils.loadAnimation(this, R.anim.anim);
    animation.setDuration(500);
    dialog.setAnimation(animation);
    dialog.animate();
    animation.start();
 }

}

这篇关于Android的使用动画的LinearLayout增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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