DIỄN ĐÀN TIN HOC
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
DIỄN ĐÀN TIN HOC

BÀI VIẾT MỚINGƯỜI GỬI CUỐI

      Thảo luận nhiều nhất

      Lượt xem nhiều nhất


      You are not connected. Please login or register

      [Android] Chuyển đổi qua lại activity với animation.

         

      nhuvannhu

      #1[Android] Chuyển đổi qua lại activity với animation. Empty Mon May 26, 2014 3:20 pm

      nhuvannhu
      nhuvannhu Quản lý viên

      Giới tính : Nam

      Tổng số bài gửi Tổng số bài gửi : 18

      Points Points : 57

      Like Like : 3

      status : Không có gì để nói



      Project demo [You must be registered and logged in to see this link.]
      [Android] Chuyển đổi qua lại activity với animation. GX5UZ07
      Quan trọng là các anim, mình chỉ giới thiệu 2 anim cơ bản. Còn lại trong project đã có rồi
      aimation_down_enter.xml
      Code:
      <set xmlns:android="http://schemas.android.com/apk/res/android"
          android:interpolator="@android:anim/linear_interpolator"> 
        <translate
            android:fromYDelta="-100%p"
            android:toYDelta="0%p"
            android:duration="500"/>
      </set>
      animation_down_exit.xml
      Code:
      <?xml version="1.0" encoding="utf-8"?> 
      <set xmlns:android="http://schemas.android.com/apk/res/android"
          android:interpolator="@android:anim/linear_interpolator"> 
        <translate
            android:fromYDelta="0%p"
            android:toYDelta="100%p"
            android:duration="500"/>
      </set>
      Acitivity1.java
      Code:
      import android.os.Bundle;
      import android.app.Activity;
      import android.app.PendingIntent;
      import android.content.Intent;
      import android.view.Menu;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;

      public class Activity1 extends Activity {

         @Override
         protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button btnUp = (Button) findViewById(R.id.btnUp);
            Button btnLeft = (Button) findViewById(R.id.btnRight);
            btnUp.setOnClickListener(onClickListener);
            btnLeft.setOnClickListener(onClickListener);
         }
      public OnClickListener onClickListener = new OnClickListener() {
            
            @Override
            public void onClick(View v) {
               Intent intent = new Intent(Activity1.this, Activity2.class);
               switch (v.getId()) {
               case R.id.btnUp:
                  
                  startActivity(intent);
                  overridePendingTransition(R.anim.animation_up_enter, R.anim.animation_up_exit);
                  break;
               case R.id.btnRight :
                  startActivity(intent);
                  overridePendingTransition(R.anim.animation_right_enter, R.anim.animation_right_exit);
                  break;
               default:
                  break;
               }
               // TODO Auto-generated method stub
               
            }
         };
         @Override
         public boolean onCreateOptionsMenu(Menu menu) {

            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
         }

      }
      Acitivity2.java
      Code:
      import android.os.Bundle;
      import android.app.Activity;
      import android.content.Intent;
      import android.view.Menu;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;

      public class Activity2 extends Activity {

         @Override
         protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_activity2);
            Button btnDown = (Button) findViewById(R.id.btnDown);
            Button btnRight = (Button) findViewById(R.id.btnLeft);
            btnDown.setOnClickListener(onClickListener);
            btnRight.setOnClickListener(onClickListener);

         }

         public OnClickListener onClickListener = new OnClickListener() {

            @Override
            public void onClick(View v) {

               Intent intent = new Intent(Activity2.this, Activity1.class);
               switch (v.getId()) {
               case R.id.btnDown:

                  startActivity(intent);
                  overridePendingTransition(R.anim.animation_down_enter,
                        R.anim.animation_down_exit);
                  break;
               case R.id.btnLeft:
                  startActivity(intent);
                  overridePendingTransition(R.anim.animation_left_enter,
                        R.anim.animation_left_exit);
                  break;
               default:
                  break;
               }
               // TODO Auto-generated method stub

            }
         };

         @Override
         public boolean onCreateOptionsMenu(Menu menu) {

            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.activity2, menu);
            return true;
         }

      }
         
            

      [Trang 1 trong tổng số 1 trang]

      Thông tin chuyên mục

      Bạn không có quyền trả lời bài viết