我遇到了setContentView问题,它引发了一个空指针。在OnLongClick监听器中的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。
看到这个https://groups.google.com/forum/?fromgroups#!topic/android-developers/wj4uc0J9yT0 – Sameer 2012-07-09 09:28:02
某种程度上是没有帮助解决我的问题 – 2012-07-09 09:37:00
的setContentView()没有,直到视觉冲击* * onCreate()返回后返回 。如果你调用它两次,网络是用户将只看到 第二。 – SALMAN 2012-07-09 09:41:49