有没有一种简单的方式在Android上翻转不同的布局,而不需要使用片段。我的视图是静态的(那里什么都没有发生),但为了本地化目的,我们不会使用图像,因此我会选择布局解决方案。希望提供一个很好的示例展示这个技巧。
编辑:以下是完全工作的代码,基于下面的答案:
编辑:以下是完全工作的代码,基于下面的答案:
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
}