【发布时间】:2011-10-10 13:52:55
【问题描述】:
我有一个片段应该显示在另一个片段下的活动中
在我尝试使用的片段的 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>
(请注意布局标签中的android: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 以编程方式添加片段,并且在添加第一个片段之后添加第二个片段,但在同一个事务中
你能告诉我有什么问题吗?
谢谢
【问题讨论】: