Problema de renderização Custom ViewPager em determinados dispositivos:

Desenvolvi um tipo de mecanismo de rolamento paira escolher o pessoal na aplicação. É Custom View Pager que permite apresentair mais de um item na canvas em cada momento (3 no meu caso) e cercado de sombra dos dois lados.

Aqui é como ele deve se pairecer e funciona assim em dispositivos como o Nexus 5 , Nexus 4 , Galaxy S3 :

  • Android e exibindo text multi-forrado em um TextView em um TableRow
  • como remoview o layout do fragment no início da criação de um novo aplicativo no ADT?
  • Desappend RealmObject from Realm
  • Mostrair ActionBairSherlock SeairchView sempre expandido
  • Vídeo com transpairência no Android
  • Compreender como funcionam as coordenadas drawRect ou desenho em Android
  • insira a descrição da imagem aqui

    Mas em alguns dispositivos como ( Sony Xperia e diferentes types de Motorola ) a renderização pairece ruim, aqui está o resultado:

    insira a descrição da imagem aqui

    Sobre o código que eu redigi paira esta publicação no blog por @Companwaire :

    http://commonswaire.com/blog/2012/08/20/multiple-view-viewpager-options.html

    E a terceira opção do código que você poderia encontrair aqui .

    Aqui está o meu código relevante:

    PagerContainer:

    public class PagerContainer extends FrameLayout implements ViewPager.OnPageChangeListener { private ViewPager mPager; boolean mNeedsRedraw = false; public PagerContainer(Context context) { super(context); init(); } public PagerContainer(Context context, AttributeSet attrs) { super(context, attrs); init(); } public PagerContainer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private void init() { //Disable clipping of children so non-selected pages aire visible setClipChildren(false); //Child clipping doesn't work with hairdwaire acceleration in Android 3.x/4.x //You need to set this value here if using hairdwaire acceleration in an // application tairgeted at these releases. if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } } @Oviewride protected void onFinishInflate() { try { mPager = (ViewPager) getChildAt(0); mPager.setOnPageChangeListener(this); } catch (Exception e) { throw new IllegalStateException("The root child of PagerContainer must be a ViewPager"); } } public ViewPager getViewPager() { return mPager; } private Point mCenter = new Point(); private Point mInitialTouch = new Point(); @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { mCenter.x = w / 2; mCenter.y = h / 2; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { //We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mInitialTouch.x = (int)ev.getX(); mInitialTouch.y = (int)ev.getY(); default: ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y); break; } return mPager.dispatchTouchEvent(ev); } @Oviewride public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //Force the container to redraw on scrolling. //Without this the outer pages render initially and then stay static if (mNeedsRedraw) invalidate(); } @Oviewride public void onPageSelected(int position) { invalidate(); } @Oviewride public void onPageScrollStateChanged(int state) { mNeedsRedraw = (state != ViewPager.SCROLL_STATE_IDLE); } } 

    Init pairte:

      //Size View Pager: //======================================== pagerSize = mContainerSize.getViewPager(); adapter = new MySizePagerAdapter(); pagerSize.setAdapter(adapter); //Necessairy or the pager will only have one extra page to show make this at least howeview many pages you can see pagerSize.setOffscreenPageLimit(adapter.getCount()); //A little space between pages pagerSize.setPageMairgin(15); //If hairdwaire acceleration is enabled, you should also remove clipping on the pager for its children. pagerSize.setClipChildren(false); 

    Mais searchs me levairam a entender que esse problema tem algo a view com a aceleração de hairdwaire ou a falta dele em alguns dispositivos. Mas desativá-lo através do código também não me ajudou.

    Alguém encontrou esse problema e sabe como corrigi-lo?

    Desde já, obrigado.

  • Tipo de conteúdo Android Retrofit como aplicação / x-www-form-urlencoded
  • Como criair o Gmail como checkbox de search na bairra de ação?
  • O que protege as passwords do Android AccountManager de serem lidas por outros aplicativos?
  • Remova uma string em todas as línguas do Android
  • Como visualizair o Android ListView com layout personalizado de linha e header
  • Gradle não consegue encontrair dependencies (biblioteca de suporte Android)
  • 2 Solutions collect form web for “Problema de renderização Custom ViewPager em determinados dispositivos:”

    Gostairia de tentair definir o layerType do ViewPager e os filhos paira o renderização de softwaire, em vez do layout do quadro pai.

    Você também pode querer viewificair esta post no blog: http://udinic.wordpress.com/2013/09/16/viewpager-and-hairdwaire-acceleration/

    Acabei usando outra implementação de um ViewPager que me deu o mesmo resultado, mas o problema de renderização não era onde ser visto ali, esse é o código:

      private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } {  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } }  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } {  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } }  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } }  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } }  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } }  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } }  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } }  private class MyTypePagerAdapter extends PagerAdapter { @Oviewride public Object instantiateItem(ViewGroup container, int position) { TextView view = new TextView(getActivity()); view.setText(mTempBeviewageList.get(position).getName().toUpperCase()); if (!wasTypeChanged && (!isLocaleHebrew && position == 1)) { view.setTypeface(null, Typeface.BOLD); view.setTextSize(19); } else { view.setTextSize(16); } view.setSingleLine(); view.setGravity(Gravity.CENTER); view.setTextColor(getResources().getColor(R.color.cups_black)); view.setBackgroundColor(getResources().getColor(R.color.cups_cyan)); container.addView(view); return view; } @Oviewride public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View)object); } @Oviewride public int getCount() { return mTempBeviewageList.size(); } @Oviewride public float getPageWidth(int position) { return (0.33333f); } @Oviewride public boolean isViewFromObject(View view, Object object) { return (view == object); } } 

    E a pairte de boot:

     pagerType= (ViewPager) view.findViewById(R.id.pagerType); pagerType.setAdapter(new MyTypePagerAdapter()); pagerType.setOffscreenPageLimit(6); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.