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

Posted 冰糖葫芦三剑客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

 

 

 

 

以上是关于Android Activity 淡入淡出和从底部向上弹出动画效果的主要内容,如果未能解决你的问题,请参考以下文章

Android四大组件——Activity跳转动画淡出淡入滑出滑入自定义退出进入

Android 创建淡入淡出动画的详解

Android属性动画小练习(简单实现旋转平移淡入淡出缩放动画效果)

ListView的淡入淡出和Activity的淡入淡出补间动画效果Animation

当用户滚动到页面的最底部时淡入/淡出固定位置 div

android 怎么做淡入淡出效果