我想使用动画使布局出现在屏幕上。这个想法是布局从高度为0开始增长到100%。
我遇到了麻烦,需要一些帮助。出于某种原因,没有执行任何动画。
这是我的动画XML文件:
<?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>
布局文件非常基础,并且设计如下
<?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>
我的活动代码也非常基本
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.
}
}
谢谢你