Android 无法显示两个片段(静态),即使我可以分别显示每个片段
我是android的初学者,所以我可能会错过一些简单的东西,但我有一个“奇怪的问题”。我有两个片段,当我想单独显示它们时,我可以成功地显示它们。现在我想并排显示它们,我写了以下内容,但它只显示第二个片段。(frag2) 这是我活动中的xmlAndroid 无法显示两个片段(静态),即使我可以分别显示每个片段,android,android-studio,android-fragments,Android,Android Studio,Android Fragments,我是android的初学者,所以我可能会错过一些简单的东西,但我有一个“奇怪的问题”。我有两个片段,当我想单独显示它们时,我可以成功地显示它们。现在我想并排显示它们,我写了以下内容,但它只显示第二个片段。(frag2) 这是我活动中的xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<fragment class="com.example.frag1"
android:id="@+id/fragone"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment class="com.example.frag2"
android:id="@+id/fragtwo"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
您将它们的
布局\u宽度
设置为匹配\u父项
,因此其中一个被推出线性布局的侧面
。正确的修复方法是什么?我应该分配权重吗?这是一个选项。如果您想让它们的宽度相同,请将它们的layout\u width
s设置为0dp
,将它们的layout\u weight
s设置为1
。实际上,这里已经讨论了好几次了,因此我将其作为类似问题的重复关闭。不过谢谢你。很高兴这对你有用。干杯
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout_activity_main);
}