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

How do new media operators choose promotion channels?

Recently, I saw a very thought-provoking question...

Thermos cup is a must-have in winter, how can you buy a safe one?

Now that the weather is getting colder, many peop...

The smell you love so much can actually promote nerve regeneration?

Compiled by: Gong Zixin Known for its rich, earth...

[Edible Fungi Science] Cultural Legends of Lingzhi

Cultural legend of Lingzhi Lingzhi spore powder h...

Switching between HStack and VStack in SwiftUI

Preface SwiftUI’s various stacks are the most bas...

E-commerce operations: analysis of the promotion system!

E-commerce has been integrated into our lives and...

How does live streaming boost sales?

Undoubtedly, the strong rise of live streaming e-...

Community operation: Why are more and more communities dying?

In the past two years, social networks have becom...

Aiti Tribe Stories (7): Meet 51CTO and aim high

[51CTO.com original article] The protagonist of t...

Ganfanren Yiyi_How to create a vertical account for beginners video

The course from Ganfanren Yiyi teaches beginners ...

Just three steps to let you play Hammer phone "Big Bang"

Whether it is business office, online social netw...