Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
Created August 25, 2015 04:06
Show Gist options
  • Save hkurokawa/4eea1801c39c339d1ed7 to your computer and use it in GitHub Desktop.
Save hkurokawa/4eea1801c39c339d1ed7 to your computer and use it in GitHub Desktop.
SurfaceView を足そうとすると画面が点滅する ref: http://qiita.com/hkurokawa/items/e80f6525005b81bb5636
<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"
tools:context=".MainActivity">
<!-- Somehow, if you add a SurfaceView in advance, the screen does not blink. -->
<SurfaceView
android:layout_width="0dp"
android:layout_height="0dp"/>
<Button
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: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