2012-05-21 19 views
7

が所定の空き領域を残す:Androidの表示/非表示断片は

  1. 最初現在選択されている断片(ViewFlipper)で
  2. 処置テキストベース切り替わり画面上の2つの垂直に配置された要素(ViewPagerおよびフラグメント) WebViewベースのビューを表示し、下部のフラグメントを非表示/表示します。観測

  1. 底断片を非表示には、底断片が配置されている空き領域を残します。

下の断片を除去した後、私はまだ下

上の空きスペースを持ってここでトップレベルのレイアウトファイルだ私は(weight=1にセットトップ断片と)相対とのLinearLayoutの両方を試してみましたが、両方は効果がありません:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" android:layout_weight="1"/> 

<!-- This gets replaced with appropriate fragment at run time --> 
<LinearLayout 
    android:id="@+id/scrollFragmentPlaceholder" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="110dip" /> 
</LinearLayout> 

ここフラグメント

Fragment scroll = getSupportFragmentManager().findFragmentById(R.id.scrollFragment); 
    if (scroll.isHidden() == isWebView) 
     return; // already handled, do nothing 
    FragmentTransaction tr = getSupportFragmentManager().beginTransaction(); 
    if (scroll != null && scroll.isAdded()) { 
     if (isWebView) { 
      tr.hide(scroll); 
     } else 
      tr.show(scroll); 
    } 
    tr.commit(); 

そして、ここを切り替えコードがありますどのように見えるの: Bottom fragment is hidden

+0

は、あなたが(* .MEASUREをやってみました作業するためのフラグメントを表示/非表示にしたい

public void onJobViewToggled(final boolean isWebView) { if (isFinishing()) return; final Fragment scroll = getSupportFragmentManager().findFragmentById(R.id.scrollFragment); if (scroll.isHidden() == isWebView) return; // already handled, do nothing final FragmentTransaction tr = getSupportFragmentManager().beginTransaction(); if (scroll != null && scroll.isAdded()) { if (isWebView) { tr.hide(scroll); // shell is the original placeholder shell.setVisibility(View.GONE); } else { tr.show(scroll); shell.setVisibility(View.VISIBLE); } } tr.commit(); } 

注)のままのビューに? – Codeman

+0

実際にはそうではありませんが、注文を裏返してテキストのバージョン/隠しボトムが正しく表示されていれば – Bostone

+0

アンドロイドのWebViewは血まみれです。いくつかのスクリーンショットを追加して、具体的に何を話しているのか分かりますか?また、両方のビューでlayoutWeight = 1を使用する必要がある場合は、両方のビューでlayoutWeight = 1を使用する必要があります。親ビューでorientation = "vertical"を指定する必要があります。 – Codeman

答えて

16

私はそれを行う方法を考え出した。フラグメントを隠すだけでは不十分だと分かりますが、基本的にフラグメントを含むシェルを非表示にする必要があります。もともとXMLで定義されていたLinearLayoutです。実際には、フラグメントを表示/非表示にするために、元のレイアウトで可視性を設定するだけで十分です。そこで質問からのコードは次のようになります。あなたはまだ、これは

+1

どのようにシェルを取得していますか? – Nick

関連する問題