2017-02-18 65 views
0

我有兩個WebView,當potrait,它位於上方和下方,但橫向時,將其分爲左和右。兩個WebView更改拆分方向不重新加載視圖

我已成功創建它,並更改onCreateView中的方向視圖並保持狀態,但它會重新加載web視圖並顯示阻止應用程序顯示的加載彈出窗口。我認爲有人知道如何在不重新加載應用程序的情況下改變拆分方向?

電流法:

View v = null; 
    if (getResources().getConfiguration().orientation == 
      Configuration.ORIENTATION_PORTRAIT) { 
     v = inflater.inflate(R.layout.fragment_potrait, container, false); 
    } else { 
     v = inflater.inflate(R.layout.fragment_landscape, container, false); 
    } 

enter image description here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/parent_view" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:fitsSystemWindows="true" 
       xmlns:spl="http://schemas.android.com/apk/res-auto" 
       tools:context=".MainActivity"> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     tools:context=".MainActivity"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:visibility="gone" 
      > 
      <View 
       android:layout_width="match_parent" 
       android:layout_height="64dp" 
       android:background="@color/light_gray" 
       app:layout_scrollFlags="scroll|enterAlways" 
       /> 
     </android.support.design.widget.AppBarLayout> 

     <SplitPaneLayout 
      android:layout_width = "fill_parent" 
      android:layout_height = "fill_parent" 
      android:layout_marginTop="?attr/actionBarSize" 
      spl:splitterPosition="43%" 
      spl:orientation="vertical" 
      spl:splitterBackground="@drawable/splitter_bg_h" 
      spl:splitterDraggingBackground="#F0F0F0" 
      > 
      <WebView 
       android:id="@+id/webview1" 
       android:layout_width = "fill_parent" 
       android:layout_height = "0dp" 
       android:text = "YOUR FIRST TEXT" 
       android:layout_weight = "1" 
       android:autoLink="web|all" 
       android:scrollbars="none" 
       android:textColor="@android:color/black" 
       /> 
      <WebView 
       android:id="@+id/webview2" 
       android:layout_width = "fill_parent" 
       android:layout_height = "0dp" 
       android:text = "YOUR SECOND TEXT" 
       android:autoLink="web|all" 
       android:scrollbars="none" 
       android:textColor="@android:color/black" 
       android:layout_weight = "1" 
       /> 
     </SplitPaneLayout> 
    </android.support.design.widget.CoordinatorLayout> 
</RelativeLayout> 

我用這個拆分窗格: https://github.com/MobiDevelop/android-split-pane-layout

回答

0

在運行Android的應選擇縱向/橫向佈局。

通過聲明:

android:configChanges="keyboardHidden|orientation|screenSize" 

onCreate,和onDestroy不叫而是onConfigurationChanged被調用。你可以用這種方法處理你想以編程方式進行的一切!

更多信息,請參閱Handling Configuration Changes

+0

它不回答這個問題是:*?如何**改變分割方向**無需重新加載應用程序* – Selvin