階層を減らすために階層ビューアーを使用しているときに、フラグメントを追加するたびに (「静的」または「動的」の両方の方法で) フラグメントが常に新しい FrameLayoutにラップされることに気付きました。
次に例を示します。
これは私の活動のレイアウトです:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="mainActivityRoot" >
<TextView
android:id="@+id/hello_world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<fragment
android:name="com.example.testfragments.MainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/hello_world" />
</RelativeLayout>
そして、これはフラグメントのレイアウトです:
<ProgressBar android:id="@+id/ProgressBar1" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:contentDescription="mainFragmentRoot"
android:layout_height="match_parent" />
アクティビティのソース コードは 以外は空ですsetContentView
, フラグメントのソース コードには のみが含まれます
@Override
public View onCreateView(...) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
今、
アクティビティ ルートの階層に直接表示されることを期待しますがPrograssBar
、その代わりに、どこから来たのかわからない追加の FrameLayout があります。余分なフレームを黄色でペイントしたスクリーン ショットを次に示します。
それで、私の質問は - それはどこから来たのですか? そして、私はそれを取り除くことができますか? 私の実際のアプリケーションでは、これらの余分な FrameLayout が非常に深い階層を作成しており、おそらくパフォーマンスが低下しています。
ありがとう!