我认为标题涵盖了它:) 我有一个可绘制的对象,它可以获取 .png 照片,我可以用手势操作它。我还有一个带有背景图像的 xml 布局,它应该位于这个可绘制对象的后面。一切都发生在一个片段中。
当我运行代码并到达这个片段时,会显示 png 并且手势可以工作,但是,没有膨胀的布局并且在后退按钮按下应用程序崩溃(我猜那是因为我在片段中使用 setContentView 所以有没有后栈?我该如何避免这种情况?)。
稍后我将在场景中添加其他图层。
我的问题是,我怎样才能同时使用 xml 布局来膨胀片段,在其上显示可绘制对象,以及稍后在所有这些之上添加其他视图?
此片段的代码如下所示:
public class RoomFragment extends Fragment {
ViewGroup mRoot;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mRoot = (ViewGroup) inflater.inflate(R.layout.room_fragment, null);
/** Placing furniture .png element in SandboxView */
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.furniture);
View view = new SandboxView(this.getActivity(), bitmap);
this.getActivity().setContentView(view); // Replace with inflater?
return mRoot;
}}
谢谢!