0

[Web ページである] チュートリアル ページのリストを読み込むチュートリアル アプリがあります。これらのページは全画面表示になり、メニュー バー用に約 100 dp が残ります。ソースコードをそのまま共有することはできませんが、Tutorial Activity の疑似コードを以下に示します。

HashMap<Integer, customWebView > mapPage;
onCreate(){
    updateScreen();
}


updateScreen(){
    Instantiate CustomScrollView(Customized HorizontalScrollView);
    Instantiate scrollViewChildHolder (LinearLayout with horizontal orientation);
    Instantiate mapPage;
        for  index : total page size{
            Instantiate pageHolder(RelativeLayout);
            Instantiate customWebView (Custom WebView);//Takes orientation as one of argument
            Set  html page url;//customWebView has a method loadWebPage() which loads this url.
            Add customWebView  to pageHoler;
            mapPage.put(index, customWebView);
            Add pageHolder to  scrollViewChildHolder;
        }
    //pageNo which will be safely fetched from saved state. So it will be 1 on first start 
    //and on orientation change retains current reading page.
    onPageChange(pageNo);
}

//Custom callback on page swipe by user
@Override
onPageChange(int  pageNo){
    //Custom method which loads html page from url which was set in updateScreen() 
    mapPage.get(pageNo).loadWebPage();
    //unloadNeighbouring pages
    //Will  pick pageNo+2 & pageNo-2 pages and clears their content.
    unloadNeighbouringPagesTo(pageNo);
}

PS:

  1. WebView にいくつかのボタンを追加する必要があるため、RelativeLayout をページ ラッパーとして使用します。

  2. アダプター [ViewPager の PagerAdapter] を選択することはできません。これは、WebView がロード時にコンテンツを突然フラッシュするため、余裕がありません。したがって、CustomHorizo​​ntalSrollView は必須です。

  3. スクロールビューに約 150 以上のページを追加します。

  4. ランドスケープモードとポートレートモード用に別々のページがあります。したがって、方向の変更時に再作成する必要があります。また、表示サイズは画面の向きごとに異なります。

  5. onConfigurationChanged(..) をオーバーライドしていません。つまり、向きが変わると、Activity のライフ サイクルは新しいものから始まります。

問題:

向きを変えると、ページ コンテンツの読み込みに 2 ~ 3 秒かかります。また、アプリが向きの変化をかなり遅く検出しているようです。

方向変更時のクイックロードのパフォーマンスを改善する方法を提案してください。

4

1 に答える 1

0

横向きと縦向きの両方のデザインを含む単一のレイアウト ファイルを作成することができます。OnConfigurationChange(); をオーバーライドします。

mnifest.xml

<activity
            android:name="YourActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" // this will not refresh your activity
             />

@Override
    public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);

        if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
            //visible landscape layout
            //hide portrait layout
        }else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            //visible portrait layout
            //hide landscape layout
        }
    }
于 2013-09-03T08:46:36.317 に答える