Android Activity 淡入淡出和从底部向上弹出动画效果

这篇博客介绍了如何在Android应用中实现Activity的淡入淡出以及从底部向上弹出的动画效果。通过在anim文件夹下创建XML动画资源文件,并在AnimationActivity.java中进行相应的代码实现,可以为用户带来更丰富的交互体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

         在优快云上注册账户好久了,一直都是学习各位大牛的技术,技巧。今天也试试自己写一些东西,希望对大家也有帮助。第一次写希望各位指点帮助。
     我在做手机界面的时候,碰到很多Activity淡出,或者是从下到上,弹出的效果。通过查找资料自己做出来终于实现了这中效果,和大家分享下。首先看下效果图:

 
 
 
动画效果Activity淡入,同按钮布局有屏幕底部向上推出,代码比较简单就不在这里详细介绍。
 
1.首先创建一个,的布局文件clearpan.xml,这个文件就是从下到上弹出的布局文件。

    
<?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" >
    <!-- android:background="@drawable/clearpanbackground" -->
    
 <RelativeLayout
     android:id="@+id/clearallpan"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:background="@drawable/incall_bg"
     >
     
     <Button
         android:id="@+id/clearall"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_marginLeft="10dip"
         android:layout_marginRight="10dip"
         android:layout_marginTop="20dip"
         android:layout_marginBottom="10dip"
      android:background="@drawable/iphonesms_smsdetail_delete_deleteall"
         android:text="删除所有"
         android:textColor="#FFFFFFFF"/>
     
     <Button
         android:id="@+id/cancel"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_marginLeft="10dip"
         android:layout_marginRight="10dip"
         android:layout_marginTop="10dip"
         android:layout_marginBottom="20dip"
         
         android:text="取消"
      android:background="@drawable/iphonesms_smsdetail_delete_forwardall"
         android:layout_below="@id/clearall"
         android:textColor="#FFFFFFFF"/>
     
 </RelativeLayout>
    
</RelativeLayout>



2.在anim文件夹下,定义动画效果文件

    

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


<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >
    <translate
        android:duration="300"
        android:fromYDelta="100.0%"
        android:toYDelta="10.000002%" />
    <alpha
        android:duration="50"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

3 .创建AnimationActivity.java代码类。


   public class AnimationActivity extends Activity {
   private Button mBtu;
   private String mStr;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mBtu = (Button) findViewById(R.id.clear);
        mBtu.setOnClickListener(new OnClickListener() {
         private AlertDialog dlg = null;
         
   Button mCancelBtn = null;
   Button mClearAllBtn = null;
   
   @Override
   public void onClick(View v) {
    this.dlg = new AlertDialog.Builder(AnimationActivity.this)
    .create();
  View localView = AnimationActivity.this.getLayoutInflater()
    .inflate(R.layout.clearpan, null);
  localView.setAnimation(AnimationUtils.loadAnimation(
    AnimationActivity.this, R.anim.slide_bottom_to_top));
  Window localWindow = this.dlg.getWindow();
  localWindow.getAttributes();
  this.dlg.show();
  localWindow.setContentView(localView);
  localWindow.setGravity(Gravity.BOTTOM);
  localWindow.setLayout(-1, 280);
  this.mClearAllBtn = ((Button) this.dlg
    .findViewById(R.id.clearall));
  this.mCancelBtn = ((Button) this.dlg
    .findViewById(R.id.cancel));
  this.mClearAllBtn.setOnClickListener(new View.OnClickListener() {
   public void onClick(View paramView) {
    finish();
   }
  });
 
  this.mCancelBtn.setOnClickListener(new View.OnClickListener() {
   public void onClick(View paramView) {
    dlg.cancel();
   }
  });
   }
   
  });
        
    }
}
      


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值