Android viewpager only flips layouts, not fragments

Is there a simple way to switch between different layouts without using clips on Android? My view is static (nothing happens there), but for localization purposes, we won't use images, so I'll look for a layout solution

I would appreciate a good example of this technique

Edit:

This is the complete working code based on the following answers:

public class LayoutPagerAdapter : PagerAdapter
    {
        Context m_context;
        readonly int[] m_slideLayoutResourceIds;

        public LayoutPagerAdapter(Context context, int[] slideLayoutResourceIds)
        {
            m_context = context;
            m_slideLayoutResourceIds = slideLayoutResourceIds;
        }

        public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
        {
            var inflater = LayoutInflater.From(m_context);

            var view = inflater.Inflate(m_slideLayoutResourceIds[position], container, false);

            container.AddView(view);

            return view;
        }

        public override void DestroyItem(View container, int position, Java.Lang.Object objectValue)
        {
            base.DestroyItem(container, position, objectValue);
        }

        #region implemented abstract members of PagerAdapter

        public override bool IsViewFromObject(View view, Java.Lang.Object objectValue)
        {
            return view == objectValue;
        }

        public override int Count
        {
            get
            {
                return m_slideLayoutResourceIds.Length;
            }
        }

        #endregion
    }

resolvent:

You can create your own simple adapter for this:

public static class ViewPagerAdapter extends PagerAdapter {

  private Context mContext;

  public ViewPagerAdapter(Context context) {
    mContext = context;
  }

  @Override
  public View instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.your_layout, container, false);

    return view;
  }

  @Override
  public int getCount() {
    return 5;
  }

  @Override
  public boolean isViewFromObject(View view, Object object) {
    return view == object;
  }

}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>