0

我正在使用视图寻呼机和寻呼机适配器进行用户滑动。我的要求是,我有三个列表视图,即 0、1、2。首次启动时,我需要显示第一个列表视图,即索引位置 1。当用户向左滑动时,我必须显示 0 索引位置列表视图的 40% 和第二个索引位置 1 列表视图的 60%(在同一视图中),当用户向右滑动时,我必须显示 50% 的索引位置 1 列表视图和 50% 的索引位置 2 列表视图(在同一视图中)。在过去的几天里,我一直在努力如何得到这个。请给我解决此问题的解决方案。

我的代码是

private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity_main);

    ListView listview1 = new ListView(mContext);
    ListView listview2 = new ListView(mContext);
    ListView listview3 = new ListView(mContext);

    Vector<View> pages = new Vector<View>();

    pages.add(listview1);
    pages.add(listview2);
    pages.add(listview3);

    ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
    CustomPagerAdapter adapter = new CustomPagerAdapter(mContext,pages);
    vp.setAdapter(adapter);
    vp.setCurrentItem(1);
     listview1.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,new String[]{"A1","B1","C1","D1"}));
    listview2.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,new String[]{"A2","B2","C2","D2"}));
    listview3.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,new String[]{"A3","B3","C3","D3"}));
    }

自定义页面适配器

公共类 CustomPagerAdapter 扩展 PagerAdapter {

    private Context mContext;
    private Vector<View> pages;
    View page;
    int i=0;
    public CustomPagerAdapter(Context context, Vector<View> pages) {
         this.mContext=context;
         this.pages=pages;
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
         page = pages.get(position);
            container.addView(page);
         Log.i("venkat2", "is" + position);
         //position=position * 2;
         return page;
    }
            @Override
    public int getCount() {
            return pages.size();
            }
            @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //Log.i("venkat3", "is" + "3");
         container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        //Log.i("venkat4", "is" + "4");
          return view.equals(object);
    }

感谢和问候, Venkatesan.R

4

0 回答 0