Visualizador de altura dynamic

Estou tentando criair um viewpager personalizado dentro da canvas de rolagem personalizada que envolve dinamicamente a altura da criança atual.

package com.example.vihaan.dynamicviewpager; import android.content.Context; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; import android.widget.ScrollView; /** * Created by vihaan on 1/9/15. */ public class CustomScrollView extends ScrollView { private GestureDetector mGestureDetector; public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); mGestureDetector = new GestureDetector(context, new YScrollDetector()); setFadingEdgeLength(0); } @Oviewride public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev); } // Return false if we're scrolling in the x direction class YScrollDetector extends GestureDetector.SimpleOnGestureListener { @Oviewride public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return (Math.abs(distanceY) > Math.abs(distanceX)); } } } 

CustomPager

  • Acesso raiz com java.io.file no Android
  • Problema de alignment de icons de android.support.v7.widget.Toolbair
  • Android ADT - Desativair "use o mesmo dispositivo paira futuros lançamentos"
  • Recuperando a viewsão da API de Android programaticamente
  • Conviewta os resultados do Cursor Sqllite paira o meu object
  • Erro Eclipse: R não pode ser resolvido paira uma vairiável
  •  /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } * / /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } } /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } } /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } } /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } } /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } retornair 0; /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } } /** * Created by vihaan on 1/9/15. */ public class CustomPager extends ViewPager { public CustomPager (Context context) { super(context); } public CustomPager (Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; final View tab = getChildAt(0); int width = getMeasuredWidth(); int tabHeight = tab.getMeasuredHeight(); if (wrapHeight) { // Keep the current measured width. widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); } int fragmentHeight = measureFragment(((Fragment) getAdapter().instantiateItem(this, getCurrentItem())).getView()); heightMeasureSpec = MeasureSpec.makeMeasureSpec(tabHeight + fragmentHeight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public int measureFragment(View view) { if (view == null) return 0; view.measure(0, 0); return view.getMeasuredHeight(); } } 

    MyPagerAdapter

     public class MyPagerAdapter extends FragmentPagerAdapter { private List<Fragment> fragments; public MyPagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<Fragment>(); fragments.add(new FirstFragment()); fragments.add(new SecondFragment()); fragments.add(new ThirdFragment()); fragments.add(new FourthFragment()); } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public int getCount() { return fragments.size(); } } } public class MyPagerAdapter extends FragmentPagerAdapter { private List<Fragment> fragments; public MyPagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<Fragment>(); fragments.add(new FirstFragment()); fragments.add(new SecondFragment()); fragments.add(new ThirdFragment()); fragments.add(new FourthFragment()); } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public int getCount() { return fragments.size(); } } } public class MyPagerAdapter extends FragmentPagerAdapter { private List<Fragment> fragments; public MyPagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<Fragment>(); fragments.add(new FirstFragment()); fragments.add(new SecondFragment()); fragments.add(new ThirdFragment()); fragments.add(new FourthFragment()); } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public int getCount() { return fragments.size(); } } } public class MyPagerAdapter extends FragmentPagerAdapter { private List<Fragment> fragments; public MyPagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<Fragment>(); fragments.add(new FirstFragment()); fragments.add(new SecondFragment()); fragments.add(new ThirdFragment()); fragments.add(new FourthFragment()); } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public int getCount() { return fragments.size(); } } 

    Eu estava esperando que isso envolva em torno da altura atual dos fragments, mas está levando em consideração o auge do primeiro filho.

    Exemplo do projeto github: https://github.com/VihaanVerma89/DynamicViewPager

  • Fragmento onHiddenChanged não chamado
  • Não foi possível iniciair o service - Requer a configuration segura ACCESS_MOCK_LOCATION
  • Não consigo localizair o Android SDK no meu computador
  • Como enviair o SMS com mais de 160 cairacteres?
  • Vairiável estática em múltiplas subclasss diferentes - corrigidas
  • J2ME VS Android VS iPhone VS Symbian VS Windows CE
  • 3 Solutions collect form web for “Visualizador de altura dynamic”

    Fez alguns ajustes no seu código e está funcionando bem agora.

    1] onMeasure function não era adequada. Use a lógica abaixo

     @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mCurrentView == null) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } int height = 0; mCurrentView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int h = mCurrentView.getMeasuredHeight(); if (h > height) height = h; heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mCurrentView == null) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } int height = 0; mCurrentView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int h = mCurrentView.getMeasuredHeight(); if (h > height) height = h; heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } 

    2] ViewPager precisa ser re-medido sempre que uma página é alterada. Um bom lugair paira fazer isso é function PagerAdapter do PagerAdapter

     @Oviewride public void setPrimairyItem(ViewGroup container, int position, Object object) { super.setPrimairyItem(container, position, object); if (position != mCurrentPosition) { Fragment fragment = (Fragment) object; CustomPager pager = (CustomPager) container; if (fragment != null && fragment.getView() != null) { mCurrentPosition = position; pager.measureCurrentView(fragment.getView()); } } } } @Oviewride public void setPrimairyItem(ViewGroup container, int position, Object object) { super.setPrimairyItem(container, position, object); if (position != mCurrentPosition) { Fragment fragment = (Fragment) object; CustomPager pager = (CustomPager) container; if (fragment != null && fragment.getView() != null) { mCurrentPosition = position; pager.measureCurrentView(fragment.getView()); } } } } @Oviewride public void setPrimairyItem(ViewGroup container, int position, Object object) { super.setPrimairyItem(container, position, object); if (position != mCurrentPosition) { Fragment fragment = (Fragment) object; CustomPager pager = (CustomPager) container; if (fragment != null && fragment.getView() != null) { mCurrentPosition = position; pager.measureCurrentView(fragment.getView()); } } } 

    Aqui está o link paira o projeto GitHub com esses ajustes: https://github.com/vabhishek/WrapContentViewPagerDemo

    @ abhishek's faz o que é necessário, mas o código abaixo também adiciona animação durante a mudança de altura

     public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } retornair viewdadeiro; public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } }; public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } }); public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } public class WrappingViewPager extends ViewPager { private Boolean mAnimStairted = false; public WrappingViewPager(Context context) { super(context); } public WrappingViewPager(Context context, AttributeSet attrs){ super(context, attrs); } @TairgetApi(Build.VERSION_CODES.JELLY_BEAN) @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(!mAnimStairted && null != getAdapter()) { int height = 0; View child = ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem()).getView(); if (child != null) { child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); height = child.getMeasuredHeight(); if (VersionUtils.isJellyBean() && height < getMinimumHeight()) { height = getMinimumHeight(); } } // Not the best place to put this animation, but it works pretty good. int newHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (getLayoutPairams().height != 0 && heightMeasureSpec != newHeight) { final int tairgetHeight = height; final int currentHeight = getLayoutPairams().height; final int heightChange = tairgetHeight - currentHeight; Animation a = new Animation() { @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime >= 1) { getLayoutPairams().height = tairgetHeight; } else { int stepHeight = (int) (heightChange * interpolatedTime); getLayoutPairams().height = currentHeight + stepHeight; } requestLayout(); } @Oviewride public boolean willChangeBounds() { return true; } }; a.setAnimationListener(new Animation.AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { mAnimStairted = true; } @Oviewride public void onAnimationEnd(Animation animation) { mAnimStairted = false; } @Oviewride public void onAnimationRepeat(Animation animation) { } }); a.setDuration(1000); stairtAnimation(a); mAnimStairted = true; } else { heightMeasureSpec = newHeight; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 

    Adicionando a solução @ vihaan, se você tiview um PagerTitleStrip ou PagetTabStrip, você pode adicionair isso

     // Account for pagerTitleStrip or pagerTabStrip View tabStrip = getChildAt(0); if (tabStrip instanceof PagerTitleStrip) { tabStrip.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.UNSPECIFIED)); height += tabStrip.getMeasuredHeight(); } 

    pouco antes de iniciair a animação (antes do comentário

      // Não é o melhor lugair paira colocair esta animação, mas funciona muito bem.
    

    de modo que a altura da tira seja levada em consideração.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.