我有应该在另一个片段集碎片中的Android活动
在片段的XML的活动中显示一个片段中的位置我试着使用:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/second_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10sp"
android:layout_below="@id/first_fragment">
<TextView
android:id="@+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:focusable="false"
android:clickable="false"
android:textSize="20sp"
android:padding="5sp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
(请注意机器人:layout_below = “@ ID/first_fragment” 布局标签)
我也试过这样:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/first_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10sp">
<TextView
android:id="@+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:focusable="false"
android:clickable="false"
android:textSize="20sp"
android:padding="5sp"
android:layout_centerHorizontal="true"
android:layout_below="@id/first_fragment"/>
</RelativeLayout>
(请注意TextView标签中的android:layout_below =“@ id/first_fragment”)
在这两种情况下,应用程序都会编译并运行,但第二个片段显示在屏幕的顶部而不是第一个。
请考虑我用FragmentTransaction编程添加片段,我添加第二个片段,具有添加的第一个之后,但在相同的交易
能否请你告诉我,什么是错的?
感谢信
嗯,我没有标签活动的XML。我有两个xml和两个片段类(每个片段一个)。我通过使用FragmentTransaction来添加这两个片段。在两个片段类的onCreateView中,我膨胀通讯员xml来创建并返回片段的视图 –
kingston
我必须使用android SDK 3.0或更高版本。 – Thiru
我的意思是我的活动视图是通过使用不包含任何片段的xml来夸大的。我稍后添加片段。我使用兼容性支持库 – kingston