渲染视图来查看传呼机 - 优化的方式 [英] Rendering Views to View Pager - Optimized Way

查看:143
本文介绍了渲染视图来查看传呼机 - 优化的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我用下面的方法来渲染/生成到一个视图寻呼机的看法。是的,它工作正常,如预期。

In my application I am using the following means to render/generate the views to a view pager. Yes it works fine and as expected.

注意: - 但这里我所看到的,这种方法已经投入了大量的精力在Android的资源(与设备关联)条款。我想找出任何优化的方式做同样的。是否有什么?我建议还是上面的好?

Note :- But here I have seen that this method has to put a lot of effort in terms of Android resources ( associated with the device). I want to find out any optimized way to do the same. Is there is any? Suggest me or the above is good ?

class MyActivity extends Activity{
        @Override
        public void onCreate(Bundle savedInstanceState) {

             super.onCreate(savedInstanceState);
            setContentView(R.layout.layoutView);

            LinearLayout pageFirst = getPageFisrt(context);
            LinearLayout pageSecond = getPageSecond(context);
            LinearLayout pageThird = getPageThird(context);
            LinearLayout pageFourth = getPageFourth(context);
            .........
            .........

            pageArrayList = new ArrayList<LinearLayout>();
            pageArrayList.clear();

            pageArrayList.add(pageFirst);
            pageArrayList.add(pageSecond);
            pageArrayList.add(pageThird);
            pageArrayList.add(pageFourth);
            ...........
            ..........

            viewPager.setAdapter(new MatchDetailsPagerAdapter(
                    context, pageArrayList));

            indicator.setViewPager(viewPagerMatchDetailMain);

        }

    }

和每一页我膨胀的布局从资源, 像

and for each page I inflated the layout from resource, like

   private LinearLayout getPageFisrt(Context context) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = LayoutInflater.from(context);
        LinearLayout linearLayoutFirstPage = (LinearLayout) inflater.inflate(
                R.layout.pager_first_large_views, null);

       // performing action on the page child layout.

        return linearLayoutFirstPage;
    }

期待一个更好的方法做同样的

Looking forward for a better approach to do the same

推荐答案

我认为,用碎片与 FragmentPagerAdapter 更优化,然后生成所有layot​​s在的onCreate 方法。

I think,to use fragments with FragmentPagerAdapter more optimized ,then generate all layots in onCreate method.

public class FragmentAdapter extends FragmentPagerAdapter
    implements IconPagerAdapter
{    
    private int count = 2;

    public InstallFragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {     
        switch (position) {
            case 0:
                return Fragment0.newInstance();
            case 1:
                return Fragment1.newInstance();
            case 2:
                return Fragment2.newInstance();
            default:
                break;
        }
        return null;
    }

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

    @Override
    public CharSequence getPageTitle(int position) {
        return "";
    }

    @Override
    public int getIconResId(int position) {
        return 0;
    }
}

这篇关于渲染视图来查看传呼机 - 优化的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆