【发布时间】:2013-05-27 13:55:36
【问题描述】:
虽然使用hierarchy viewer 来减少层次结构,但我注意到在每次添加片段时(以“静态”或“动态”方式),片段总是包裹在 新的 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 会创建非常深的层次结构,这可能对性能不利。
谢谢!
【问题讨论】:
标签: android performance view android-fragments