ViewPager application guide page and viewpager guide page
When this reference is enabled for a boot page, the image is first animated. When the animation ends, the boot page is displayed.
The following small image is displayed when ViewPager disappears and then click it.
It is worth learning to enable the animation on the Interface first.
Package com. demo. activity; import com. demo. pullrefresh. r; import android. app. activity; import android. content. intent; import android. content. sharedPreferences; import android. OS. bundle; import android. view. animation. alphaAnimation; import android. view. animation. animation; import android. view. animation. animation. animationListener; import android. view. animation. animationSet; import android. view. animation. rotat EAnimation; import android. view. animation. scaleAnimation; import android. widget. relativeLayout;/*** pop-up page ** @ author Administrator **/public class SplashActivity extends Activity {private RelativeLayout rl_root; @ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); setContentView (R. layout. splashactivity); rl_root = (Re LativeLayout) findViewById (R. id. rl_root); startAnim ();}/*** enable animation */private void startAnim () {// TODO Auto-generated method stub // Animation set AnimationSet = new AnimationSet (false); // rotate the Animation RotateAnimation rotate = new RotateAnimation (0,360, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); rotate. setDuration (1000); // set the animation time to rotate. setFillAfter (true); // sets the animation state // scales the animation Sca LeAnimation scale = new ScaleAnimation (0, 1, 0, 1, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); scale. setDuration (1000); scale. setFillAfter (true); // gradient animation AlphaAnimation alpha = new AlphaAnimation (0, 1); alpha. setDuration (1, 2000); alpha. setFillAfter (true); set. addAnimation (rotate); set. addAnimation (scale); set. addAnimation (alpha); // sets an animation listener set. setAnimationListener (new Anima TionListener () {@ Override public void onAnimationStart (Animation arg0) {// TODO Auto-generated method stub} @ Override public void onAnimationRepeat (Animation arg0) {// TODO Auto-generated method stub} // @ Override public void onAnimationEnd (Animation arg0) {// TODO Auto-generated method stub startActivity (new Intent (SplashActivity. this, GuideActivity. class); finish () ;}}); rl_root.st ArtAnimation (set);}/*** go to the next page */private void jumpNextPage () {SharedPreferences sPreferences = getSharedPreferences ("infos", MODE_PRIVATE); boolean isuserGuid = sPreferences. getBoolean ("key", false); if (! IsuserGuid) {// enter the boot page startActivity (new Intent (SplashActivity. this, GuideActivity. class);} else {startActivity (new Intent (SplashActivity. this, MainActivity. class) ;}finish ();}}
On the guide page
Package com. demo. activity; import java. util. arrayList; import com. demo. pullrefresh. r; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. support. v4.view. pagerAdapter; import android. support. v4.view. viewPager; import android. support. v4.view. viewPager. onPageChangeListener; import android. view. view; import android. view. viewGroup; import android. view. viewTreeObserver. onGlobalLayoutListener; import android. view. window; import android. widget. button; import android. widget. imageView; import android. widget. linearLayout; import android. widget. relativeLayout; public class GuideActivity extends Activity {/*** image data */private static final int [] mImageIds = new int [] {R. drawable. guide_1, R. drawable. guide_2, R. drawable. guide_3}; private ArrayList <ImageView> mImageViewList;/*** ViewPager implementation */private ViewPager vPager; private LinearLayout llPointGroup; // The parent control of the Guide origin, private View viewRedPoint; // private int mPointWidth; // The distance between the dots is private Button btnStart; // go to other interfaces/*** set a button to hide the Layout of ViewPager and display it when you click it */private ImageView igv_image; private RelativeLayout rl_one; private boolean visibility_flag; @ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. activity_guide); vPager = (ViewPager) findViewById (R. id. vp_guide); llPointGroup = (LinearLayout) findViewById (R. id. ll_point_group); viewRedPoint = findViewById (R. id. view_red_position); btnStart = (Button) findViewById (R. id. btn_start); igv_image = (ImageView) findViewById (R. id. igv_image); rl_one = (RelativeLayout) findViewById (R. id. rl_one); initViews (); vPager. setAdapter (new GuideAdapter (); vPager. setOnPageChangeListener (new GuidePageListener (); igv_image.setOnClickListener (new View. onClickListener () {@ Override public void onClick (View arg0) {// TODO Auto-generated method stub if (visibility_flag) {rl_one.setVisibility (View. VISIBLE); visibility_flag = false;} else {rl_one.setVisibility (View. INVISIBLE); visibility_flag = true ;}}); btnStart. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View arg0) {// TODO Auto-generated method stub startActivity (new Intent (GuideActivity. this, MainProducte. class); finish () ;}});}/*** initialization interface */private void initViews () {// TODO Auto-generated method stub mImageViewList = new ArrayList <ImageView> (); // initialize the three guided interfaces for (int I = 0; I <mImageIds. length; I ++) {ImageView imageView = new ImageView (this); imageView. setBackgroundResource (mImageIds [I]); mImageViewList. add (imageView);} // initialize the small dot of the boot page for (int I = 0; I <mImageIds. length; I ++) {View pointView = new View (this); pointView. setBackgroundResource (R. drawable. shape_point_gray); LinearLayout. layoutParams params = new LinearLayout. layoutParams (10, 10); if (I> 0) {params. leftMargin = 10; // set the dot interval} pointView. setLayoutParams (params); // sets the llPointGroup of the dot size. addView (pointView);} // retrieves the view tree and listens to llPointGroup for layout end events. getViewTreeObserver (). addOnGlobalLayoutListener (new OnGlobalLayoutListener () {// call back this method after layout execution ends @ Override public void onGlobalLayout () {// TODO Auto-generated method stub llPointGroup. getViewTreeObserver (). removeGlobalOnLayoutListener (this); mPointWidth = llPointGroup. getChildAt (1 ). getLeft ()-llPointGroup. getChildAt (0 ). getLeft (); System. out. println ("dot distance: ----" + mPointWidth );}});} /*** ViewPager data adapter ** @ author Administrator **/class GuideAdapter extends PagerAdapter {@ Override public int getCount () {// TODO Auto-generated method stub return mImageIds. length;} // determine whether the interface is generated by the Object @ Override public boolean isViewFromObject (View view, object) {// TODO Auto-generated method stub return view = Object; // It is used to determine the page you are currently displaying} // The interface for initializing the position is similar to the baseAdapter's getView method @ Override public Object instantiateItem (ViewGroup container, int position) {// TODO Auto-generated method stub container. addView (mImageViewList. get (position); return mImageViewList. get (position);} // destroy the position interface @ Override public void destroyItem (ViewGroup container, int position, Object object) {// TODO Auto-generated method stub // super. destroyItem (container, position, object); container. removeView (View) object );}} /*** sliding listener for ViewPager ** @ author Administrator **/class GuidePageListener implements OnPageChangeListener {// sliding event @ Override public void trim (int position, float positionOffset, int positionOffsetPixels) {// TODO Auto-generated method stub System. out. println ("Current position:" + position + "; percentage:" + positionOffset + "; moving distance:" + positionOffsetPixels); int len = (int) (mPointWidth * positionOffset + position * mPointWidth); RelativeLayout. layoutParams params = (RelativeLayout. layoutParams) viewRedPoint. getLayoutParams (); // get the current red layout parameter params. leftMargin = len; // set the left-side distance from viewRedPoint. setLayoutParams (params); // set the layout parameter for the red dot again} // a page is selected @ Override public void onPageSelected (int position) {// TODO Auto-generated method stub if (position = mImageIds. length-1) {// The last page btnStart. setVisibility (View. VISIBLE);} else {btnStart. setVisibility (View. INVISIBLE) ;}}// the sliding status changes @ Override public void onPageScrollStateChanged (int state) {// TODO Auto-generated method stub }}}<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent"> <RelativeLayout android: id = "@ + id/rl_one" android: layout_width = "match_parent" android: layout_height = "400dp"> <android. support. v4.view. viewPager android: id = "@ + id/vp_guide" android: layout_width = "match_parent" android: layout_height = "match_parent"/> <Button android: id = "@ + id/btn_start" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: Rule = "true" android: layout_centerHorizontal = "true" android: layout_marginBottom = "50dp" android: background = "@ drawable/btn_guide_selector" android: padding = "5dp" android: visibility = "invisible" android: text = "Next" android: textColor = "@ drawable/resize"/> <RelativeLayout android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentBottom = "true" android: layout_centerHorizontal = "true" android: layout_marginBottom = "15dp"> <LinearLayout android: id = "@ + id/ll_point_group" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "horizontal"> </LinearLayout> <View android: id = "@ + id/view_red_position" android: layout_width = "8dp" android: layout_height = "8dp" android: background = "@ drawable/shape_point_red"/> </RelativeLayout> <RelativeLayout android: layout_below = "@ id/rl_one" android: layout_width = "match_parent" android: layout_height = "match_parent" android: background = "# eee"> <ImageView android: id = "@ + id/igv_image" android: layout_width = "40dp" android: layout_height = "40dp" android: src = "@ drawable/ic_launcher" android: layout_centerInParent = "true"/> </RelativeLayout>View Code <? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: state_pressed = "true" android: color = "@ android: color/black"> </item> <item android: color = "@ android: color/white"/> </selector>View Code