Android source code, imitating Dianping pull-down animation

Android source code, imitating Dianping pull-down animation

Source code introduction: Imitate the pull-down sliding animation effect of Dianping, and slide with the pull-down.

Source code effect:

Source code snippet:

  1. package com.eoe.commenttogelter.ui;
  2.   
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.   
  6. import android.annotation.SuppressLint;
  7. import android.os.Bundle;
  8. import android.support.v4.app.Fragment;
  9. import android.support.v4.app.FragmentActivity;
  10. import android.support.v4.app.FragmentManager;
  11. import android.support.v4.app.FragmentPagerAdapter;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.widget.ImageView;
  15. import android.widget.TabHost;
  16. import android.widget.TabHost.OnTabChangeListener;
  17. import android.widget.TextView;
  18.   
  19. import com.eoe.commenttogelter.R;
  20.   
  21. public   class MainActivity extends FragmentActivity {
  22. private TabHost mTabHost;
  23. private NoSlideViewPager mViewPager;
  24. private List<fragment> mFragments = new ArrayList<fragment>();
  25.   
  26. @Override  
  27. protected   void onCreate(Bundle savedInstanceState) {
  28. super .onCreate(savedInstanceState);
  29. setContentView(R.layout.activity_main);
  30.   
  31. mFragments.add( new MainFragment());
  32. mFragments.add( new PurchaseFragment());
  33. mFragments.add( new SearchFragment());
  34. mFragments.add( new MineFragment());
  35.   
  36. mViewPager = (NoSlideViewPager) findViewById(R.id.content);
  37. mViewPager.setOffscreenPageLimit(mFragments.size());
  38. mViewPager.setAdapter( new ViewAdapter(getSupportFragmentManager()));
  39. mViewPager.setScanScroll( false );
  40.   
  41. mTabHost = (TabHost) findViewById(android.R.id.tabhost);
  42. mTabHost.setup();
  43.   
  44. mTabHost.addTab(mTabHost.newTabSpec( "0" ).setIndicator(createView( 0 ))
  45. .setContent(android.R.id.tabcontent));
  46. mTabHost.addTab(mTabHost.newTabSpec( "1" ).setIndicator(createView( 1 ))
  47. .setContent(android.R.id.tabcontent));
  48. mTabHost.addTab(mTabHost.newTabSpec( "2" ).setIndicator(createView( 2 ))
  49. .setContent(android.R.id.tabcontent));
  50. mTabHost.addTab(mTabHost.newTabSpec( "3" ).setIndicator(createView( 3 ))
  51. .setContent(android.R.id.tabcontent));
  52. mTabHost.setOnTabChangedListener( new OnTabChangeListener() {
  53.   
  54. @Override  
  55. public   void onTabChanged(String tabId) {
  56. int index = Integer.parseInt(tabId);
  57. mViewPager.setCurrentItem(index, false );
  58. mTabHost.getTabContentView().setVisibility(View.GONE);
  59. }
  60. });
  61. mTabHost.setCurrentTab( 0 );
  62. }
  63.   
  64. @SuppressLint ( "NewApi" )
  65. private View createView( int tabIndex) {
  66. View view = LayoutInflater.from( this ).inflate(R.layout.tabwidget_view,
  67. null );
  68. TextView tv = (TextView) view.findViewById(R.id.tv);
  69. ImageView img = (ImageView) view.findViewById(R.id.img);
  70. switch (tabIndex) {
  71. case   0 :
  72. tv.setText( "Home" );
  73. img.setImageResource(R.drawable.icon_home);
  74. break ;
  75. case   1 :
  76. tv.setText( "Group Purchase" );
  77. img.setImageResource(R.drawable.icon_tuan);
  78. break ;
  79. case   2 :
  80. tv.setText( "discover" );
  81. img.setImageResource(R.drawable.icon_search);
  82. break ;
  83. case   3 :
  84. tv.setText( "my" );
  85. img.setImageResource(R.drawable.icon_my);
  86. break ;
  87. }
  88. return view;
  89.   
  90. }
  91.   
  92. private   class ViewAdapter extends FragmentPagerAdapter {
  93.   
  94. public ViewAdapter(FragmentManager fm) {
  95. super (fm);
  96. }
  97.   
  98. @Override  
  99. public Fragment getItem( int position) {
  100. return mFragments.get(position);
  101. }
  102.   
  103. @Override  
  104. public   int getCount() {
  105. return mFragments.size();
  106. }
  107.   
  108. }
  109. }
  110. </fragment></fragment>

Download address: http://download..com/data/2104430

<<:  Android source code, excellent pedometer

>>:  A collection of the pitfalls you will encounter when adapting to iOS 9

Recommend

3 reasons and solutions for the current low app opening rate

The open rate is a KPI indicator that all operati...

How to quickly get started with Xcode 6 in iOS development

【51CTO translation】Each version update of Xcode f...

I am a flasher, not an experienced driver!

I'm a brush machine dealer. Compared with the...

APP operation and promotion: 7 strategies to improve retention!

Many people think that users are retained as long...

Three major pitfalls in developing WeChat mini-programs

Trap 1: "Mini Program Third-Party Platform&q...

Teach you how to do user operations in 3 minutes

In this era, whoever owns the users will be the k...

Ideas and techniques for creating an Internet celebrity store!

In the past few years, the streets were full of d...

The five core actions of B Station’s brand operation and deployment!

Nowadays, Bilibili has become one of the most pop...

E-commerce short video pyramid creation method (Part 1)

Many Douyin merchants always face the dilemma of ...

Taobao Live is not a panacea!

At the end of last year, I was still attending va...

Tips for writing Weibo operation plans!

Many new media operators probably have only a vag...