当设备是平板电脑(横向)时,我想添加两个片段。但是我得到了下一个错误:java.lang.IllegalArgumentException: No view found for id 0x7f0d006d (com.example.placesearch1:id/container2) for fragment FragMap
我创建了两个布局: main_activity( for phone ):
<FrameLayout
android:id="@+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true">
</FrameLayout>
和 main_activity(用于平板电脑横向- activity_main.xml(sw600dp-land)):
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
>
<FrameLayout
android:id="@+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
<FrameLayout
android:id="@+id/container2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
</LinearLayout>
我有地方的 RecycleView(container1 中的 main_activity 布局)。当我单击该项目时,我会得到一个地点的纬度和经度,并将值与 bundle 一起传递给 Map 片段,然后将地图放入其中一个容器中:如果设备是手机,则在容器 1 中,但如果设备是平板电脑,则在容器 2 中.
如果设备是电话它可以完美运行,但如果设备是平板电脑,那么我会收到错误消息。
在 GetPlace 方法中:
Bundle bundle = new Bundle();
bundle.putDouble("lat", place.getLat());
bundle.putDouble("lng", place.getLng());
FragMap fragMap = new FragMap();
fragMap.setArguments(bundle);
if(getResources().getBoolean(R.bool.isTab)) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container1, new ListFragment())
.replace(R.id.container2, fragMap)
.addToBackStack(null)
.commit();
}
else {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container1, fragMap)
.addToBackStack(null)
.commit();
}
通常,当您xml
为手机或平板电脑设计文件时,文件应该相同,并且两者xml
的内容也应该相同。但是在您的手机案例中,只有一个,framelayout
但对于平板电脑,为什么有两个framelayout
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句