我遇到了 setContentView 的问题,它给我一个空指针。
在我的 mainFrame 中,我有一个小的 SurfaceView,它占据了大约 50% 的屏幕。如果您长时间单击它,我想实现一种方法,使 SurfaceView 进入全屏状态。我是这样做的:
final FrameLayout frame = (FrameLayout) findViewById(R.id.frame_layout);
frame.setOnLongClickListener(new OnLongClickListener() {
boolean clicked = false;
@Override
public boolean onLongClick(View v) {
if (clicked){
clicked = false;
(MyActivity.this).setContentView(R.layout.main);
} else {
clicked = true;
(MyActivity.this).setContentView(R.layout.fullScreen);
}
return true;
}
});
有人可以帮我解决这个问题吗?
问候
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:orientation="vertical"
android:weightSum="1"
android:background="@drawable/background_new" >
<TextView
android:text="@string/measures"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/text_measures"
android:textColor="#ff444444"
android:layout_marginTop="30dp"
android:layout_marginLeft="10dp"
/>
<ImageButton
android:contentDescription="@string/desc_edge"
android:layout_toRightOf="@id/text_measures"
android:id="@+id/edges_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/edges_black"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="30dp"
android:onClick="edge_handler"
android:background="@null"
/>
<FrameLayout
android:background="@xml/border"
android:id="@+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="35dp"
android:layout_marginRight="200dp"
android:layout_marginTop="80dp"
android:layout_below="@id/text_measures"
>
</RelativeLayout>
我知道它看起来像 FrameLayout,但不要误会它是由其他人完成的,它实际上是 SurfaceView。