一对一直播系统开发Android 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();
   }
  });
   }
   
  });
        
    }
}
 

你可能感兴趣的:(技术类)