我創建了一個Cubeview,它擴展了GLSurfaceview,我想使它透明,但不能這樣做。在GLSurfaceview中設置透明度
我已經在MainActivity中使用setZOrderOnTop() & glClearColor()在GLSurfaceview視圖類中也遵循很多link但沒有做的工作。
public class RubikActivity extends Activity {
cubeView cv;
GLSurfaceView gv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
cv = (cubeView) findViewById(R.id.cubeView);
cv.initialize(PreferenceManager.getDefaultSharedPreferences(this));
cv.requestFocus();
cv.setFocusableInTouchMode(true);
cv.setEGLConfigChooser(8, 8, 8, 8, 8,0);
// cv.setRenderer(new CubeRenderer(getApplicationContext(), font, mWorld, rCube, mMenu, prefs);
cv.getHolder().setFormat(PixelFormat.TRANSLUCENT);
cv.setZOrderOnTop(true);
}
CubeView.java
public cubeView(Context context, AttributeSet attrs) {
super(context, attrs);
font = new TextureFont(getContext(), R.drawable.roboto_regular, "roboto_regular_dims.txt");
mWorld = new GLWorld();
}
public void initialize(SharedPreferences prefs) {
rCube = new Rubec(mWorld, prefs.getInt("dim", 3));
mMenu = new CubeMenu(rCube, font);
_renderer = new CubeRenderer(getContext(), font, mWorld, rCube, mMenu, prefs);
rCube.setRenderer(_renderer);
mWorld.setRubeCube(rCube);
setRenderer(_renderer);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
setZOrderOnTop(true);
}
CubeRenderer.java
public void onDrawFrame(GL10 g) {
GL11 gl = (GL11)g;
surfaceSetup(gl);
gl.glClearColor(0,0,0,1);
gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
}
我要透明Cubeview
隨機嘗試 - 'surfaceView.setEGLContextClientVersion(2); surfaceView.setZOrderOnTop(true); surfaceView.setEGLConfigChooser(8,8,8,8,16,0); surfaceView.getHolder()。setFormat(PixelFormat.RGBA_8888);' – Kiran
@Kiran我有嘗試但不適合我................... n謝謝你的幫助我 –