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] View Switcher with animation

         

      nhuvannhu

      #1[Android] View Switcher with animation Empty Thu May 29, 2014 10:44 am

      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] View Switcher with animation N2DVVX9[Android] View Switcher with animation 9CycaTo
      ActivityViewSwitcher.java
      Code:

      import android.os.Bundle;
      import android.app.Activity;
      import android.view.Menu;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.view.animation.Animation;
      import android.view.animation.AnimationUtils;
      import android.widget.AdapterView;
      import android.widget.AdapterView.OnItemClickListener;
      import android.widget.Button;
      import android.widget.ViewSwitcher;

      public class ActivityViewSwitcher extends Activity {
         
         private ViewSwitcher viewSwitcher ;
         private Button btnSwitcher1;
         private Button btnSwitcher2;

         @Override
         protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_view_switcher);
            viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
            btnSwitcher1 = (Button) findViewById(R.id.btnSwitcher1);
            btnSwitcher2 = (Button) findViewById(R.id.btnSwitcher2);
            btnSwitcher1.setOnClickListener(onClickListener);
            btnSwitcher2.setOnClickListener(onClickListener);
         }
         
         private OnClickListener onClickListener = new OnClickListener() {
            
            @Override
            public void onClick(View v) {
            
               // TODO Auto-generated method stub
               switch (v.getId()) {
               case R.id.btnSwitcher1:   
                  //animation down.
                  Animation animation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.animation_down_exit);
                  viewSwitcher.setAnimation(animation);
                  viewSwitcher.showNext();
                  break;
               case R.id.btnSwitcher2:
                  viewSwitcher.setAnimation(AnimationUtils.makeInAnimation(getBaseContext(), true));
                  viewSwitcher.showPrevious();
                  break;
               default:
                  break;
               }
            }
         };
         @Override
         public boolean onCreateOptionsMenu(Menu menu) {

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

      }
      activity_view_switcher.xml
      Spoiler:
      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>
         
            

      [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