分享

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

 anio17 2017-03-29


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

    

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas./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./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. }  



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多