android仿微信的開門效果

來源:互聯網
上載者:User

有人已經發過了,我掐頭去尾精簡了一下 

 

 
這種效果跟圖和布局有很大關係,並不難。 

先看布局: 

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <LinearLayout         android:id="@+id/layout"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical"        android:background="@drawable/whatsnew_bg"        android:gravity="center_horizontal|bottom"        android:visibility="visible"        >        <Button              android:id="@+id/btn_start"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="開始我的性生活"              android:textSize="18sp"              android:textColor="#FFFFFFFF"              android:background="@drawable/button_bg"  android:layout_marginBottom="20dip"              />    </LinearLayout>    <LinearLayout         android:id="@+id/animLayout"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="horizontal"        >        <LinearLayout            android:id="@+id/leftLayout"             android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:layout_weight="1"            >        <ImageView             android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:src="@drawable/whatsnew_left"            android:layout_weight="1"            />        <ImageView             android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/whatsnew_left_m"            />        </LinearLayout>        <LinearLayout             android:id="@+id/rightLayout"             android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:layout_weight="1"            >        <ImageView             android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/whatsnew_right_m"            />        <ImageView             android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:src="@drawable/whatsnew_right"            android:layout_weight="1"            />        </LinearLayout>    </LinearLayout></LinearLayout>

在看代碼: 

package com.dl.app;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.view.animation.Animation.AnimationListener;import android.widget.Button;import android.widget.LinearLayout;public class TestOpenDoorActivity extends Activity {private Context context;private Button btn_start;private LinearLayout layout;private LinearLayout animLayout;private LinearLayout leftLayout;private LinearLayout rightLayout;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        this.context=this;        initViews();            }        private void initViews(){    btn_start=(Button)findViewById(R.id.btn_start);    btn_start.setOnClickListener(onClickListener);        layout = (LinearLayout) findViewById(R.id.layout);    animLayout = (LinearLayout) findViewById(R.id.animLayout);leftLayout  = (LinearLayout) findViewById(R.id.leftLayout);rightLayout  = (LinearLayout) findViewById(R.id.rightLayout);    }        View.OnClickListener onClickListener=new View.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.btn_start:doOpenDoor();break;default:break;}}        };        private void doOpenDoor(){        layout.setVisibility(View.GONE);    animLayout.setVisibility(View.VISIBLE);    Animation leftOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_left);Animation rightOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_right);leftLayout.setAnimation(leftOutAnimation);rightLayout.setAnimation(rightOutAnimation);leftOutAnimation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {leftLayout.setVisibility(View.GONE);rightLayout.setVisibility(View.GONE);Intent intent = new Intent(context,OtherActivity.class);startActivity(intent);finish();overridePendingTransition(R.anim.zoom_out_enter, R.anim.zoom_out_exit);}});    }}

其他見附件:

  • TestOpenDoor.zip (643.3 KB)我精簡過的
  • TestWeiXinWhatsNew.rar (1.8 MB)
  • 描述: 別人的

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.