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

A little change on the table may enhance your immunity

Sometimes, food is also medicine, and more and mo...

MOTO 360 second generation has upgraded performance and battery life

Unlike the Android-powered Nexus, Google has not ...

Landwind X2 released: Why is the small SUV market so valued?

When many manufacturers saw the huge market poten...

This dolphin attacked more than 40 people, and it just wanted to make friends?

On the Tsuruga Peninsula in Fukui Prefecture, Jap...

Will iOS 9 become more stable?

iOS has undergone tremendous changes since iOS 7,...

How to write good copy? Here’s a [universal little formula] for you!

Although some people say that there is a group of...

What exactly does community operation do?

Community operation has always been a difficult p...

Use 3 tricks to easily promote your product

For a large, mature company, promoting a new prod...

How do K12 online education companies build their own distribution systems?

The current situation of online education compani...

2023 Nobel Prize in Chemistry: The periodic table now has a third dimension

The 2023 Nobel Prize in Chemistry was awarded for...