English 中文(简体)
记忆问题与观点与分类
原标题:Memory issue with ViewPager

目前,我正在开发一种使用感想器的仪器,问题是,我这样做的方式使开始和接收记忆的步伐极其缓慢。

I m 安装类似页数:

        public MyPagerAdapter(Context context) {
        views = new ArrayList<RelativeLayout>();
        views.add(new SliderLayout(context, "slide 8"));
        views.add(new SliderLayout(context, "slide 1"));
        views.add(new SliderLayout(context, "slide 2"));
        views.add(new SliderLayout(context, "slide 3"));
        views.add(new SliderLayout(context, "slide 4"));
        views.add(new SliderLayout(context, "slide 5"));
        views.add(new SliderLayout(context, "slide 6"));
        views.add(new SliderLayout(context, "slide 7"));
        views.add(new SliderLayout(context, "slide 8"));
        views.add(new SliderLayout(context, "Slide 1"));
    }

All the layoutobjects contain a FrameLayout with a textView and a panel that contains a webview with local html. All the layouts have unique content, that is loaded and inflated when the SliderLayout class is instantiated.

我还试图就即时飞行的飞行补充看法。 项目方法,但这只是使滚动变得更有活力,如果我动得太快,就会给外派造成致命的例外。

So my question is, what is the best way to implement a ViewPager that contains several unique views (but based on the same layout), so it doesn t consume so much memory and starts quicker?

最佳回答

您必须把自己的意见附在瞬时电传上(如你在常规改装器时采用“意见”方法)。 在这种情况下,GiPager负责记忆管理。 考察资格认证的脱摩项目。 实际上,你可以有数千页,没有任何滞后。

@Override
public Object instantiateItem(View collection, int position) {
    View v = layoutInflater.inflate(...);
    ...
    ((ViewPager) collection).addView(v,0);
    return tv;
}

@Override
public void destroyItem(View collection, int position, Object view) {
    ((ViewPager) collection).removeView((TextView) view);
}
问题回答

hm, my idea is to catch the event "onPageChanged()" in the ViewPager and set the webview after the page has changed - or, to preload as example a page so you have the "scroll effect": you do the following:

as example, you have a count of 10 pages. if your viewpager is at page 0, then you instanciate and load the pages 0,1,2. if your viewpager is at screen 4, then you remove the webviews at positions 0,1 and 7,8,9...

in this way you dont need all instances of webviews (webkit consumes a lot of memory) and have some more memory.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签