打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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


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

    

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.       
  6.     android:orientation="vertical" >  
  7.     <!-- android:background="@drawable/clearpanbackground" -->  
  8.       
  9.  <RelativeLayout   
  10.      android:id="@+id/clearallpan"  
  11.      android:layout_width="fill_parent"  
  12.      android:layout_height="wrap_content"  
  13.      android:layout_alignParentBottom="true"  
  14.      android:background="@drawable/incall_bg"  
  15.      >  
  16.        
  17.      <Button   
  18.          android:id="@+id/clearall"  
  19.          android:layout_width="fill_parent"  
  20.          android:layout_height="wrap_content"  
  21.          android:layout_marginLeft="10dip"  
  22.          android:layout_marginRight="10dip"  
  23.          android:layout_marginTop="20dip"  
  24.          android:layout_marginBottom="10dip"  
  25.       android:background="@drawable/iphonesms_smsdetail_delete_deleteall"  
  26.          android:text="删除所有"  
  27.          android:textColor="#FFFFFFFF"/>  
  28.        
  29.      <Button   
  30.          android:id="@+id/cancel"  
  31.          android:layout_width="fill_parent"  
  32.          android:layout_height="wrap_content"  
  33.          android:layout_marginLeft="10dip"  
  34.          android:layout_marginRight="10dip"  
  35.          android:layout_marginTop="10dip"  
  36.          android:layout_marginBottom="20dip"  
  37.            
  38.          android:text="取消"  
  39.       android:background="@drawable/iphonesms_smsdetail_delete_forwardall"  
  40.          android:layout_below="@id/clearall"  
  41.          android:textColor="#FFFFFFFF"/>  
  42.        
  43.  </RelativeLayout>  
  44.       
  45. </RelativeLayout>  

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

  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3.   
  4.   
  5. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  6.     android:interpolator="@android:anim/accelerate_interpolator" >  
  7.     <translate  
  8.         android:duration="300"  
  9.         android:fromYDelta="100.0%"  
  10.         android:toYDelta="10.000002%" />  
  11.     <alpha  
  12.         android:duration="50"  
  13.         android:fromAlpha="0.0"  
  14.         android:toAlpha="1.0" />  
  15. </set>  


3 .创建AnimationActivity.Java代码类。

  1.  public class AnimationActivity extends Activity {  
  2.    private Button mBtu;  
  3.    private String mStr;  
  4.     /** Called when the activity is first created. */  
  5.     @Override  
  6.     public void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.main);  
  9.         mBtu = (Button) findViewById(R.id.clear);  
  10.         mBtu.setOnClickListener(new OnClickListener() {  
  11.          private AlertDialog dlg = null;  
  12.            
  13.    Button mCancelBtn = null;  
  14.    Button mClearAllBtn = null;  
  15.      
  16.    @Override  
  17.    public void onClick(View v) {  
  18.     this.dlg = new AlertDialog.Builder(AnimationActivity.this)  
  19.     .create();  
  20.   View localView = AnimationActivity.this.getLayoutInflater()  
  21.     .inflate(R.layout.clearpan, null);  
  22.   localView.setAnimation(AnimationUtils.loadAnimation(  
  23.     AnimationActivity.this, R.anim.slide_bottom_to_top));  
  24.   Window localWindow = this.dlg.getWindow();  
  25.   localWindow.getAttributes();  
  26.   this.dlg.show();  
  27.   localWindow.setContentView(localView);  
  28.   localWindow.setGravity(Gravity.BOTTOM);  
  29.   localWindow.setLayout(-1, 280);  
  30.   this.mClearAllBtn = ((Button) this.dlg  
  31.     .findViewById(R.id.clearall));  
  32.   this.mCancelBtn = ((Button) this.dlg  
  33.     .findViewById(R.id.cancel));  
  34.   this.mClearAllBtn.setOnClickListener(new View.OnClickListener() {  
  35.    public void onClick(View paramView) {  
  36.     finish();  
  37.    }  
  38.   });  
  39.     
  40.   this.mCancelBtn.setOnClickListener(new View.OnClickListener() {  
  41.    public void onClick(View paramView) {  
  42.     dlg.cancel();  
  43.    }  
  44.   });  
  45.    }  
  46.      
  47.   });  
  48.           
  49.     }  
  50. }  



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android屏幕适配不同的资源图片、布局
Android 设置页面UI设计
向android 的状态栏中加入快捷按钮(home,back,menu等等)的方法(续) ...
Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
【安卓rom定制】丨『第三十五课』丨修改状态栏显示
LinearLayout和RelativeLayout 比较
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服