当用户按下一个按钮,我想B片段出现在左边,就像这样:片段添加到左侧
这里是我的代码现在要做到这一点:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ViewGroup
android:id="@+id/leftContainer"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0000" />
<ViewGroup
android:id="@+id/rightContainer"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#ff00ffff" />
</LinearLayout>
android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.leftContainer, fragmentA);
ft.add(R.id.rightContainer, fragmentB);
ft.commit();
不幸的是,这一切给了我一个黑色的屏幕。我甚至没有看到片段的背景颜色。
你试过有两个布局,并使用'的setContentView()'? – pqn 2012-07-23 19:37:28
我还没有尝试过,但如果我不能提出更“优雅”的解决方案,我会尝试。谢谢 – Matt 2012-07-23 19:57:06