仿微信的开门效果

有人已经发过了,我掐头去尾精简了一下 

 

 
这种效果跟图和布局有很大关系,并不难。 
先看布局: 
Xml代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <LinearLayout   
  8.         android:id="@+id/layout"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="fill_parent"  
  11.         android:orientation="vertical"  
  12.         android:background="@drawable/whatsnew_bg"  
  13.         android:gravity="center_horizontal|bottom"  
  14.         android:visibility="visible"  
  15.         >  
  16.         <Button  
  17.               android:id="@+id/btn_start"  
  18.               android:layout_width="wrap_content"  
  19.               android:layout_height="wrap_content"  
  20.               android:text="开始我的性生活"  
  21.               android:textSize="18sp"  
  22.               android:textColor="#FFFFFFFF"  
  23.               android:background="@drawable/button_bg"  
  24.               android:layout_marginBottom="20dip"  
  25.               />  
  26.     </LinearLayout>  
  27.     <LinearLayout   
  28.         android:id="@+id/animLayout"  
  29.         android:layout_width="fill_parent"  
  30.         android:layout_height="fill_parent"  
  31.         android:orientation="horizontal"  
  32.         >  
  33.         <LinearLayout  
  34.             android:id="@+id/leftLayout"   
  35.             android:layout_width="fill_parent"  
  36.             android:layout_height="fill_parent"  
  37.             android:layout_weight="1"  
  38.             >  
  39.             <ImageView   
  40.                 android:layout_width="fill_parent"  
  41.                 android:layout_height="wrap_content"  
  42.                 android:src="@drawable/whatsnew_left"  
  43.                 android:layout_weight="1"  
  44.                 />  
  45.             <ImageView   
  46.                 android:layout_width="wrap_content"  
  47.                 android:layout_height="wrap_content"  
  48.                 android:src="@drawable/whatsnew_left_m"  
  49.                 />  
  50.         </LinearLayout>  
  51.         <LinearLayout   
  52.             android:id="@+id/rightLayout"   
  53.             android:layout_width="fill_parent"  
  54.             android:layout_height="fill_parent"  
  55.             android:layout_weight="1"  
  56.             >  
  57.             <ImageView   
  58.                 android:layout_width="wrap_content"  
  59.                 android:layout_height="wrap_content"  
  60.                 android:src="@drawable/whatsnew_right_m"  
  61.                 />  
  62.             <ImageView   
  63.                 android:layout_width="fill_parent"  
  64.                 android:layout_height="wrap_content"  
  65.                 android:src="@drawable/whatsnew_right"  
  66.                 android:layout_weight="1"  
  67.                 />  
  68.         </LinearLayout>  
  69.     </LinearLayout>  
  70. </LinearLayout>  


在看代码: 
Java代码   收藏代码
  1. package com.dl.app;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.Context;  
  5. import android.content.Intent;  
  6. import android.os.Bundle;  
  7. import android.view.View;  
  8. import android.view.animation.Animation;  
  9. import android.view.animation.AnimationUtils;  
  10. import android.view.animation.Animation.AnimationListener;  
  11. import android.widget.Button;  
  12. import android.widget.LinearLayout;  
  13.   
  14. public class TestOpenDoorActivity extends Activity {  
  15.     private Context context;  
  16.     private Button btn_start;  
  17.       
  18.     private LinearLayout layout;  
  19.     private LinearLayout animLayout;  
  20.     private LinearLayout leftLayout;  
  21.     private LinearLayout rightLayout;  
  22.       
  23.     /** Called when the activity is first created. */  
  24.     @Override  
  25.     public void onCreate(Bundle savedInstanceState) {  
  26.         super.onCreate(savedInstanceState);  
  27.         setContentView(R.layout.main);  
  28.         this.context=this;  
  29.         initViews();  
  30.           
  31.     }  
  32.       
  33.     private void initViews(){  
  34.         btn_start=(Button)findViewById(R.id.btn_start);  
  35.         btn_start.setOnClickListener(onClickListener);  
  36.           
  37.         layout = (LinearLayout) findViewById(R.id.layout);  
  38.         animLayout = (LinearLayout) findViewById(R.id.animLayout);  
  39.         leftLayout  = (LinearLayout) findViewById(R.id.leftLayout);  
  40.         rightLayout  = (LinearLayout) findViewById(R.id.rightLayout);  
  41.           
  42.     }  
  43.       
  44.     View.OnClickListener onClickListener=new View.OnClickListener(){  
  45.   
  46.         @Override  
  47.         public void onClick(View v) {  
  48.             // TODO Auto-generated method stub  
  49.             switch (v.getId()) {  
  50.             case R.id.btn_start:  
  51.                 doOpenDoor();  
  52.                 break;  
  53.   
  54.             default:  
  55.                 break;  
  56.             }  
  57.         }  
  58.           
  59.     };  
  60.       
  61.     private void doOpenDoor(){  
  62.           
  63.         layout.setVisibility(View.GONE);  
  64.         animLayout.setVisibility(View.VISIBLE);  
  65.         Animation leftOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_left);  
  66.         Animation rightOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_right);  
  67.           
  68.         leftLayout.setAnimation(leftOutAnimation);  
  69.         rightLayout.setAnimation(rightOutAnimation);  
  70.         leftOutAnimation.setAnimationListener(new AnimationListener() {  
  71.             @Override  
  72.             public void onAnimationStart(Animation animation) {  
  73.             }  
  74.             @Override  
  75.             public void onAnimationRepeat(Animation animation) {  
  76.             }  
  77.             @Override  
  78.             public void onAnimationEnd(Animation animation) {  
  79.                 leftLayout.setVisibility(View.GONE);  
  80.                 rightLayout.setVisibility(View.GONE);  
  81.                 Intent intent = new Intent(context,OtherActivity.class);  
  82.                 startActivity(intent);  
  83.                 finish();  
  84.                 overridePendingTransition(R.anim.zoom_out_enter, R.anim.zoom_out_exit);  
  85.             }  
  86.         });  
  87.           
  88.     }  
  89. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值