-1
我有自定义的surfaceview,我想覆盖其他视图。当我调用setZOderOnTop时,surfaceview消失(true)
所以我试着下面的答案。 how to make surfaceview transparent
当我在我的自定义表面视图上调用setZOderOnTop(true)时,它很快覆盖了其他视图。但是短时间后Surfaceview会消失。
当我开启/关闭我的android设备时,Surfaceview也会很快出现。
我不知道为什么会出现这种情况。请帮帮我!
有我的主要活动的onCreate
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
int sample_id=R.drawable.d7d;
piece_size=105;
sample= BitmapFactory.decodeResource(this.getResources(),
sample_id);
int returnv[] = centercrop(sample.getWidth(),sample.getHeight());
int ncols=returnv[0]/piece_size;
int nrows=returnv[1]/piece_size;
returnv[0]=ncols*piece_size;
returnv[1]=nrows*piece_size;
sample=getResizedBitmap(sample,returnv[0],returnv[1]);
Bundle config = ExampleJigsawConfigurations.customsettings(returnv[0],returnv[1],ncols,nrows,returnv[0],returnv[1],sample,sample_id,piece_size);
puzzleSurface = new PuzzleCompactSurface(this,config);
JigsawPuzzle jigsawPuzzle = new JigsawPuzzle(this, config);
puzzleSurface.setPuzzle(jigsawPuzzle);
setContentView(R.layout.puzzle_layout);
RelativeLayout surfaceView=(RelativeLayout)findViewById(R.id.surfaceframe);
surfaceView.addView(puzzleSurface);
}
布局的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:clipToPadding="false">
<include
android:id="@+id/toolbar2"
layout="@layout/toolbar2" />
<LinearLayout 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:orientation="horizontal"
android:layout_weight="1"
android:background="#F7F1EB"
android:clipToPadding="false">
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/surfaceframe"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
定制surfaceview
public PuzzleCompactSurface(Context context,Bundle config) {
super(context);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
getHolder().addCallback(this);
gameThread = new PuzzleThread(getHolder(), context, this);
this.config=config;
MAX_PUZZLE_PIECE_SIZE= config.getBundle("board").getInt("pieceSize");
CLIP=Math.round((float) 10/64 * MAX_PUZZLE_PIECE_SIZE);
setFocusable(true);
setZOrderOnTop(true);
}