【发布时间】:2016-05-06 05:53:18
【问题描述】:
我试图将同一个类放在两个不同的“FrameLayout”上。我的目标是可以将同一个对象(Processing 图形)可视化两次。
我的素描课:
public class Sketch extends PApplet {
BarChart barChart;
public void setup(){
}
public void draw(){
}
public void settings() {
size(width,height);
smooth();
}
}
我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.unicaribe.proyecto.barras.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/contenedor">
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="10dp"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="5dp"
android:id="@+id/contenedor2">
</FrameLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
我的主要活动:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment fragment= new Sketch();
FragmentManager fragmentManager= getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.contenedor, fragment)
.commit();
FragmentManager fragmentManager2= getFragmentManager();
fragmentManager2.beginTransaction()
.replace(R.id.contenedor2, fragment)
.commit();
}
我的错误是这样的
java.lang.IllegalStateException:无法更改片段 Sketch 的容器 ID{3b88ed7f id=0x7f0c0050}:原为 2131492944 现在为 2131492945
【问题讨论】:
标签: java android xml android-fragments