我对Android有点新,对碎片很新。我正试图将一个应用程序从活动移植到Honeycomb的片段(以及活动+片段)。在我们开始使用平板电脑屏幕之前,我们希望我们的应用程序能够使用针对1.6+设备的片段兼容性库。我已阅读Google的文档和示例,并没有明确说明我可以或不可以执行以下操作,但它不适用于我。您可以在Honeycomb中的碎片中构建布局吗?
移植的第一个画面是启动屏幕,其中有一个名为fragment_splash.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash_background">
<fragment class="...StartupFragmentLayout$StartupFragment"
android:id="@+id/fragStartup"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/debugText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="DEBUG ON"
android:gravity="center"
android:textSize="35sp"
android:textColor="@color/blue_text"
android:textStyle="bold"
android:shadowColor="#FFFFFF"
android:shadowRadius="2"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="bottom">
...
</fragment>
</LinearLayout>
然而,这不工作的布局文件。我收到一个错误,指出StartupFragmentLayout $ StartupFragment没有创建视图。我开始怀疑我不能在<fragment>
之内嵌套任何内容,因为我没有在任何文档或示例中看到它。这是正确的,还是我的问题别的?
既然你提到你正在使用Fragment兼容库,首先要检查的是你试图用于启动画面的Activity是从FragmentActivity扩展的。如果是这样,并且您仍然收到错误,您是否可以发布确切的错误消息和/或堆栈跟踪? – Mark
是的,我正在使用Fragment Compatibility Library。错误提示“StartupFragmentLayout $ StartupFragment没有创建视图”,它发生在setContentView(R.layout.fragment_splash);在OnCreate – CACuzcatlan
在这种情况下,我会在下面查看PJL的回复 - 看起来更符合Fragments的工作方式。 – Mark