Android 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();
   }
  });
   }
   
  });
        
    }
}

 

觉得不错的话,记得打赏一下:

https://blog.csdn.net/shenggaofei/article/details/105873568

 

 

 

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值