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

Amazing! Intestinal flora can actually metabolize nicotine?

Author: Zhao Bei Smoking is harmful to health, bu...

How to activate Baidu bidding? How to open an account and how much does it cost?

The placement of any bidding advertisements does ...

Shaluli Mountains, the central mountain range of Hengduan Mountains

Shaluli Mountain, located in the eastern part of ...

Douyin product selection strategy that novices must read

What is the most profitable thing to sell in Douy...

A brief analysis of precise audience targeting in Internet advertising!

With the development of Internet advertising tech...

The saltiest sea in the world, would you like to have a taste?

Produced by: Science Popularization China Author:...

Why is the event marketing of Pechoin and Chen Ou style so popular?

Human desires are endless, so people are greedy; ...

Why iOS consumes more power when background apps are turned off manually?

Android phone users should have a habit: when the...

New vulnerability: One song can compromise all Android devices

Security researchers at Zimperium zLabs have disc...