Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
Created August 24, 2015 22:17
Show Gist options
  • Select an option

  • Save hkurokawa/bed22b9920ec1d115f9c to your computer and use it in GitHub Desktop.

Select an option

Save hkurokawa/bed22b9920ec1d115f9c to your computer and use it in GitHub Desktop.
Screen is flashing when adding a SurfaceView
<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=".MainActivity">
<!-- Somehow, if you add a Surface view in advance, the screen does not flash. -->
<!--<SurfaceView-->
<!--android:layout_width="0dp"-->
<!--android:layout_height="0dp" />-->
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onBtnClick"
android:text="Add SurfaceView" />
<FrameLayout
android:id="@+id/content"
android:layout_below="@id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
</RelativeLayout>
package com.hkurokawa.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MainActivity extends AppCompatActivity {
ViewGroup content;
View dummy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
content = (ViewGroup) findViewById(R.id.content);
dummy = LayoutInflater.from(this).inflate(R.layout.view_dummy, content, false);
}
public void onBtnClick(View view) {
content.removeAllViews();
content.addView(dummy);
}
}
<?xml version="1.0" encoding="utf-8"?>
<SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:visibility="gone"
android:id="@+id/surface"
android:layout_width="match_parent"
android:layout_height="wrap_content"/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment