https://blog.csdn.net/junzia/article/details/73717506
2017年06月25日 14:59:39 湖广午王 阅读数:10582 标签: android opengl es 更多
个人分类: OpenGLES Android 午王
所属专栏: Android OpenGLES
版权声明:欢迎转载,转载请保留文章出处。 https://blog.csdn.net/junzia/article/details/73717506
学习在Android中使用OpenGLES,就不得不提到一个控件:GLSurfaceView。本篇博客将介绍GLSurfaceView的基本使用、GLSurfaceView的源码的简单分析,以及使用GLSurfaceView渲染图像到SurfaceView/TextureView或者PBuffer上等。
GLSurfaceView继承了SurfaceView,实现了SurfaceHolder.Callback2接口。
SurfaceView在View的基础上是创建了独立的Surface,拥有SurfaceHolder来管理它的Surface,渲染的工作可以不再在主线程中做了。可以通过SurfaceHolder得到Canvas,在单独的线程中,利用Canvas绘制需要显示的内容,然后更新到Surface上。
而GLSurfaceView,它主要是在SurfaceView的基础上实现了一个GLThread(EGLContext创建GL环境所在线程即为GL线程),绘制的工作直接通过OpenGL来进行,绘制的内容默认情况下依旧是绘制到SurfaceView所提供的Surface上。
参照GLSurfaceView的实现,我们可以自行创建GL环境,来进行GL渲染。实现自行制定指定载体、后台渲染等功能。
GLSurfaceView作为一个View,实例化上基本和其他View相当。可以选择在xml布局文件中增加,然后在Java代码中取得它的控制权。也可以在Java代码中直接new,然后呈现出来。GLSurfaceView必须加入到一个布局中,才能正确的使用,否则有可能会造成崩溃
,这和GLSurfaceView的attachToWindow和detachFromWindow中相关操作。
GLSurfaceView具有onResume和onPause两个同Activity及Fragment中的生命周期同名的方法。一般来说,在Activity或者Fragment中的onResume和onPause方法中,需要主动调用GLSurfaceView的实例的这两个方法。
GLSurfaceView的基本使用代码如下:
mGLView= (GLSurfaceView) findViewById(R.id.mGLView);
//GLContext设置为OpenGLES2.0
mGLView.setEGLContextClientVersion(2);
//在setRenderer之前,可以调用以下方法来进行EGL设置
//mGLView.setEGLConfigChooser(); //颜色、深度、模板等等设置
//mGLView.setEGLWindowSurfaceFactory(); //窗口设置
//mGLView.setEGLContextFactory(); //EGLContext设置
//设置渲染器,渲染主要就是由渲染器来决定
mGLView.setRenderer(new GLSurfaceView.Renderer(){
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
//todo surface被创建后需要做的处理
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
//todo 渲染窗口大小发生改变的处理
}
@Override
public void onDrawFrame(GL10 gl) {
//todo 执行渲染工作
}
});
/*渲染方式,RENDERMODE_WHEN_DIRTY表示被动渲染,只有在调用requestRender或者onResume等方法时才会进行渲染。RENDERMODE_CONTINUOUSLY表示持续渲染*/
mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
GLSurfaceView中,对于GL环境的操作,出queueEvent是将事件放入队列中,到GL线程中执行外,其他方法基本都是在主线程(也可以是其他线程,非当前GLSurfaceView实例的GL线程)中修改某个状态值,然后取消GL线程的等待,在GL线程中根据状态值作相应的操作,并在操作后反馈给调用方法的那个线程,当然有的方法也不需要反馈。
GLSurfaceView主要方法及中文注释如下:
public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback2 {
public final static int RENDERMODE_WHEN_DIRTY = 0;
public final static int RENDERMODE_CONTINUOUSLY = 1;
public GLSurfaceView(Context context) {
super(context);
init();
}
public GLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
//调试用的
public void setDebugFlags(int debugFlags);
public int getDebugFlags();
//设置暂停的时候是否保持EglContext
public void setPreserveEGLContextOnPause(boolean preserveOnPause);
public boolean getPreserveEGLContextOnPause();
//设置渲染器,这个非常重要,渲染工作就依靠渲染器了
//调用此方法会开启一个新的线程,即GL线程
public void setRenderer(Renderer renderer) {
checkRenderThreadState();
if (mEGLConfigChooser == null) {
mEGLConfigChooser = new SimpleEGLConfigChooser(true);
}
if (mEGLContextFactory == null) {
mEGLContextFactory = new DefaultContextFactory();
}
if (mEGLWindowSurfaceFactory == null) {
mEGLWindowSurfaceFactory = new DefaultWindowSurfaceFactory();
}
mRenderer = renderer;
mGLThread = new GLThread(mThisWeakRef);
mGLThread.start();
}
//设置EGLContext工厂,不设置就用默认的
public void setEGLContextFactory(EGLContextFactory factory);
//设置EGLSurface工厂,不设置就用默认的
public void setEGLWindowSurfaceFactory(EGLWindowSurfaceFactory factory);
//设置EglConfig,一般颜色深度等等,利用此方法设置。不设置就用默认的
public void setEGLConfigChooser(EGLConfigChooser configChooser);
//内部调用setEGLConfigChooser
public void setEGLConfigChooser(boolean needDepth);
//内部调用setEGLConfigChooser
public void setEGLConfigChooser(int redSize, int greenSize, int blueSize,
int alphaSize, int depthSize, int stencilSize);
//设置EGLContextVersion,比如2,即OpenGLES2.0
public void setEGLContextClientVersion(int version);
//设置渲染方式,有RENDERMODE_CONTINUOUSLY表示不断渲染
//以及RENDERMODE_WHEN_DIRTY表示在需要的时候才会渲染
//渲染的时候要求调用requestRender,必须在setRenderer后调用
public void setRenderMode(int renderMode);
public int getRenderMode();
//主动请求渲染
public void requestRender();
public void surfaceCreated(SurfaceHolder holder);
public void surfaceDestroyed(SurfaceHolder holder);
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h);
@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
if (mGLThread != null) {
mGLThread.requestRenderAndWait();
}
}
//生命周期,一般在Activity、Fragment的onPause中调用
public void onPause();
//生命周期,一般在Activity、Fragment的onResume中调用
public void onResume();
//向GL线程发送一个任务
public void queueEvent(Runnable r);
//附加到Window上时被调用,外部不可调用
protected void onAttachedToWindow();
//从Window上被移除时调用,外部不可调用
protected void onDetachedFromWindow();
//渲染器接口
public interface Renderer {
//Surface被创建时被调用,通常在此进行渲染的初始化
void onSurfaceCreated(GL10 gl, EGLConfig config);
//Surface大小被改变时被调用
void onSurfaceChanged(GL10 gl, int width, int height);
//执行渲染时被调用,以完成用户渲染工作
void onDrawFrame(GL10 gl);
}
//非常重要的一个EGL帮助类,GL环境的建立依靠此类
private static class EglHelper {
public EglHelper(WeakReference<GLSurfaceView> glSurfaceViewWeakRef) {
mGLSurfaceViewWeakRef = glSurfaceViewWeakRef;
}
//EGL的初始化,可以参考此方法
public void start() {
if (LOG_EGL) {
Log.w("EglHelper", "start() tid=" + Thread.currentThread().getId());
}
/*
* Get an EGL instance
*/
mEgl = (EGL10) EGLContext.getEGL();
/*
* Get to the default display.
*/
mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
throw new RuntimeException("eglGetDisplay failed");
}
/*
* We can now initialize EGL for that display
*/
int[] version = new int[2];
if(!mEgl.eglInitialize(mEglDisplay, version)) {
throw new RuntimeException("eglInitialize failed");
}
GLSurfaceView view = mGLSurfaceViewWeakRef.get();
if (view == null) {
mEglConfig = null;
mEglContext = null;
} else {
mEglConfig = view.mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);
/*
* Create an EGL context. We want to do this as rarely as we can, because an
* EGL context is a somewhat heavy object.
*/
mEglContext = view.mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
}
if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
mEglContext = null;
throwEglException("createContext");
}
if (LOG_EGL) {
Log.w("EglHelper", "createContext " + mEglContext + " tid=" + Thread.currentThread().getId());
}
mEglSurface = null;
}
//创建EGLSurface,使GL的渲染,能够渲染到用户指定的Surface
//默认的Surface就是SurfaceHolder的Surface
public boolean createSurface() {
if (LOG_EGL) {
Log.w("EglHelper", "createSurface() tid=" + Thread.currentThread().getId());
}
/*
* Check preconditions.
*/
if (mEgl == null) {
throw new RuntimeException("egl not initialized");
}
if (mEglDisplay == null) {
throw new RuntimeException("eglDisplay not initialized");
}
if (mEglConfig == null) {
throw new RuntimeException("mEglConfig not initialized");
}
/*
* The window size has changed, so we need to create a new
* surface.
*/
destroySurfaceImp();
/*
* Create an EGL surface we can render into.
*/
GLSurfaceView view = mGLSurfaceViewWeakRef.get();
if (view != null) {
mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
mEglDisplay, mEglConfig, view.getHolder());
} else {
mEglSurface = null;
}
if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
int error = mEgl.eglGetError();
if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
}
return false;
}
/*
* Before we can issue GL commands, we need to make sure
* the context is current and bound to a surface.
*/
if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
/*
* Could not make the context current, probably because the underlying
* SurfaceView surface has been destroyed.
*/
logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
return false;
}
return true;
}
//通过EGL得到GL,然后用户设置了Wrapper的话会给得到的GL做个包装
//同时也会解析一下用户的Debug意图,看看要不要debug
GL createGL();
//绘制完成之后,调用此方法,将绘制的内容输出到前台,让用户可以看到
public int swap();
//销毁Surface的方法,具体实现在destroySurfaceImp方法中
public void destroySurface();
//销毁GL环境
public void finish();
}
//GL线程,此类中存在的方法,GLSurfaceView中有同名的,
//基本都是提供给GLSurfaceView作为真正的实现调用
static class GLThread extends Thread {
//销毁EglSurface
private void stopEglSurfaceLocked();
//销毁EglContext
private void stopEglContextLocked();
//GL线程的主要逻辑都在这个方法里面,这个方法比较复杂
//GLSurfaceView的核心就在这个里面了,最后在单独分析这个里面的逻辑
private void guardedRun() throws InterruptedException;
public boolean ableToDraw() {
return mHaveEglContext && mHaveEglSurface && readyToDraw();
}
private boolean readyToDraw() {
return (!mPaused) && mHasSurface && (!mSurfaceIsBad)
&& (mWidth > 0) && (mHeight > 0)
&& (mRequestRender || (mRenderMode == RENDERMODE_CONTINUOUSLY));
}
//设置渲染方法,见GLSurfaceView的setRenderMode
public void setRenderMode(int renderMode);
public int getRenderMode();
//请求一次渲染
public void requestRender();
//请求一次渲染,并等待渲染完成
public void requestRenderAndWait();
//创建Surface
public void surfaceCreated();
//销毁Surface
public void surfaceDestroyed();
public void onPause();
public void onResume();
//Surface的大小被改变时调用
public void onWindowResize(int w, int h);
//请求退出渲染线程,并等待退出
public void requestExitAndWait();
//请求是否EglContext
public void requestReleaseEglContextLocked();
//向GL线程发送一个任务
public void queueEvent(Runnable r);
}
//debug使用的
static class LogWriter extends Writer {
}
//很多方法都会调用此方法,会检查mGLThread不为null
//即保证调用此方法的方法,必须在setRenderer之前调用
private void checkRenderThreadState();
//主要就是用来做同步用的,利用Object的wait和notifyAll
private static class GLThreadManager {
}
}
渲染的主要逻辑在GLThread的guardedRun()方法中,对guardedRun()方法梳理下。
private void guardedRun() throws InterruptedException {
mEglHelper = new EglHelper(mGLSurfaceViewWeakRef);
mHaveEglContext = false;
mHaveEglSurface = false;
mWantRenderNotification = false;
try {
GL10 gl = null;
boolean createEglContext = false;
boolean createEglSurface = false;
boolean createGlInterface = false;
boolean lostEglContext = false;
boolean sizeChanged = false;
boolean wantRenderNotification = false;
boolean doRenderNotification = false;
boolean askedToReleaseEglContext = false;
int w = 0;
int h = 0;
Runnable event = null;
while (true) {
synchronized (sGLThreadManager) {
while (true) {
//外部请求退出GL线程
if (mShouldExit) {
return;
}
/*外部请求在GL线程中处理的事件没有处理完时,就优先处理这些事件*/
if (! mEventQueue.isEmpty()) {
event = mEventQueue.remove(0);
break;
}
//暂停和恢复状态变化时,onResume和onPause状态变化
boolean pausing = false;
if (mPaused != mRequestPaused) {
pausing = mRequestPaused;
mPaused = mRequestPaused;
/*GLSurfaceView的onPause和onResume都会用wait方法等待GL线程的响应,这时候主线程阻塞。此处调用notifyAll通知onPause和onResume,放弃主线程的阻塞。GLSurfaceView中其他很多方法也存在wait方法,基本与此类似
*/
sGLThreadManager.notifyAll();
if (LOG_PAUSE_RESUME) {
Log.i("GLThread", "mPaused is now " + mPaused + " tid=" + getId());
}
}
// 需要释放EglContext时候执行的工作
if (mShouldReleaseEglContext) {
if (LOG_SURFACE) {
Log.i("GLThread", "releasing EGL context because asked to tid=" + getId());
}
stopEglSurfaceLocked();
stopEglContextLocked();
mShouldReleaseEglContext = false;
askedToReleaseEglContext = true;
}
// EglContext丢失时,销毁EglSurface和EglContext
if (lostEglContext) {
stopEglSurfaceLocked();
stopEglContextLocked();
lostEglContext = false;
}
//接收了暂停信号,而且当前EglSurface存在时,销毁EglSurface
if (pausing && mHaveEglSurface) {
if (LOG_SURFACE) {
Log.i("GLThread", "releasing EGL surface because paused tid=" + getId());
}
stopEglSurfaceLocked();
}
/*接收了暂停信号,而且当前EglContext存在时,根据用户设置,来决定是否销毁EglContext*/
if (pausing && mHaveEglContext) {
GLSurfaceView view = mGLSurfaceViewWeakRef.get();
boolean preserveEglContextOnPause = view == null ?
false : view.mPreserveEGLContextOnPause;
if (!preserveEglContextOnPause) {
stopEglContextLocked();
if (LOG_SURFACE) {
Log.i("GLThread", "releasing EGL context because paused tid=" + getId());
}
}
}
/*Surface不存在(不是EglSurface),而且当前并没有在等待Surface*/
if ((! mHasSurface) && (! mWaitingForSurface)) {
if (LOG_SURFACE) {
Log.i("GLThread", "noticed surfaceView surface lost tid=" + getId());
}
if (mHaveEglSurface) {
stopEglSurfaceLocked();
}
mWaitingForSurface = true;
mSurfaceIsBad = false;
sGLThreadManager.notifyAll();
}
// Surface存在,而且在等待Surface
if (mHasSurface && mWaitingForSurface) {
if (LOG_SURFACE) {
Log.i("GLThread", "noticed surfaceView surface acquired tid=" + getId());
}
mWaitingForSurface = false;
sGLThreadManager.notifyAll();
}
if (doRenderNotification) {
if (LOG_SURFACE) {
Log.i("GLThread", "sending render notification tid=" + getId());
}
mWantRenderNotification = false;
doRenderNotification = false;
mRenderComplete = true;
sGLThreadManager.notifyAll();
}
// 当前环境准备好了渲染执行,否则进入下一轮等待及判断
if (readyToDraw()) {
// 没有EglContext就需要借助EglHelper来创建EglContext
if (! mHaveEglContext) {
if (askedToReleaseEglContext) {
askedToReleaseEglContext = false;
} else {
try {
mEglHelper.start();
} catch (RuntimeException t) {
sGLThreadManager.releaseEglContextLocked(this);
throw t;
}
mHaveEglContext = true;
createEglContext = true;
sGLThreadManager.notifyAll();
}
}
/*有了EglContext,但是没有EglSurface,就需要设置一些状态,以便后续操作*/
if (mHaveEglContext && !mHaveEglSurface) {
mHaveEglSurface = true;
createEglSurface = true;
createGlInterface = true;
sizeChanged = true;
}
/*有eglSurface时,需要判断是否需要执行surface sizechange*/
if (mHaveEglSurface) {
if (mSizeChanged) {
sizeChanged = true;
w = mWidth;
h = mHeight;
mWantRenderNotification = true;
if (LOG_SURFACE) {
Log.i("GLThread",
"noticing that we want render notification tid="
+ getId());
}
// Destroy and recreate the EGL surface.
createEglSurface = true;
mSizeChanged = false;
}
mRequestRender = false;
sGLThreadManager.notifyAll();
if (mWantRenderNotification) {
wantRenderNotification = true;
}
//注意此处break,跳出等待的循环
break;
}
}
// By design, this is the only place in a GLThread thread where we wait().
if (LOG_THREADS) {
Log.i("GLThread", "waiting tid=" + getId()
+ " mHaveEglContext: " + mHaveEglContext
+ " mHaveEglSurface: " + mHaveEglSurface
+ " mFinishedCreatingEglSurface: " + mFinishedCreatingEglSurface
+ " mPaused: " + mPaused
+ " mHasSurface: " + mHasSurface
+ " mSurfaceIsBad: " + mSurfaceIsBad
+ " mWaitingForSurface: " + mWaitingForSurface
+ " mWidth: " + mWidth
+ " mHeight: " + mHeight
+ " mRequestRender: " + mRequestRender
+ " mRenderMode: " + mRenderMode);
}
sGLThreadManager.wait();
}
}
/*外部请求在GL线程中处理的事件没有处理完时,就优先处理这些事件*/
if (event != null) {
event.run();
event = null;
continue;
}
//后续就是根据上面的判断设置,来执行相应的操作
if (createEglSurface) {
if (LOG_SURFACE) {
Log.w("GLThread", "egl createSurface");
}
//创建EglSurface
if (mEglHelper.createSurface()) {
synchronized(sGLThreadManager) {
mFinishedCreatingEglSurface = true;
sGLThreadManager.notifyAll();
}
} else {
synchronized(sGLThreadManager) {
mFinishedCreatingEglSurface = true;
mSurfaceIsBad = true;
sGLThreadManager.notifyAll();
}
continue;
}
createEglSurface = false;
}
if (createGlInterface) {
gl = (GL10) mEglHelper.createGL();
createGlInterface = false;
}
if (createEglContext) {
if (LOG_RENDERER) {
Log.w("GLThread", "onSurfaceCreated");
}
GLSurfaceView view = mGLSurfaceViewWeakRef.get();
if (view != null) {
try {
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onSurfaceCreated");
//调用GLSurfaceView设置的renderer的onSurfceCreated方法
view.mRenderer.onSurfaceCreated(gl, mEglHelper.mEglConfig);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
}
}
createEglContext = false;
}
//surface大小被改变
if (sizeChanged) {
if (LOG_RENDERER) {
Log.w("GLThread", "onSurfaceChanged(" + w + ", " + h + ")");
}
GLSurfaceView view = mGLSurfaceViewWeakRef.get();
if (view != null) {
try {
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onSurfaceChanged");
view.mRenderer.onSurfaceChanged(gl, w, h);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
}
}
sizeChanged = false;
}
if (LOG_RENDERER_DRAW_FRAME) {
Log.w("GLThread", "onDrawFrame tid=" + getId());
}
//每帧绘制
{
GLSurfaceView view = mGLSurfaceViewWeakRef.get();
if (view != null) {
try {
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "onDrawFrame");
view.mRenderer.onDrawFrame(gl);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
}
}
}
int swapError = mEglHelper.swap();
switch (swapError) {
case EGL10.EGL_SUCCESS:
break;
case EGL11.EGL_CONTEXT_LOST:
if (LOG_SURFACE) {
Log.i("GLThread", "egl context lost tid=" + getId());
}
lostEglContext = true;
break;
default:
EglHelper.logEglErrorAsWarning("GLThread", "eglSwapBuffers", swapError);
synchronized(sGLThreadManager) {
mSurfaceIsBad = true;
sGLThreadManager.notifyAll();
}
break;
}
if (wantRenderNotification) {
doRenderNotification = true;
wantRenderNotification = false;
}
}
} finally {
/*
* clean-up everything...
*/
synchronized (sGLThreadManager) {
stopEglSurfaceLocked();
stopEglContextLocked();
}
}
}
根据上面的分析,我们知道,GLSurfaceView有setEGLWindowSurfaceFactory
借助此方法,我们可以将图像渲染到其他的地方,比如我们创建一个如下的自定义GLSurfaceView,就可以将图像渲染到外部指定surface上。但是遗憾的是,在某些手机上,这种方式会失效。
private class GLView extends GLSurfaceView{
public GLView(Context context) {
super(context);
init();
}
private void init(){
getHolder().addCallback(null);
setEGLWindowSurfaceFactory(new GLSurfaceView.EGLWindowSurfaceFactory() {
@Override
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display, EGLConfig
config, Object window) {
return egl.eglCreateWindowSurface(display,config,surface,null);
}
@Override
public void destroySurface(EGL10 egl, EGLDisplay display, EGLSurface surface) {
egl.eglDestroySurface(display, surface);
}
});
setEGLContextClientVersion(2);
setRenderer(TextureController.this);
setRenderMode(RENDERMODE_WHEN_DIRTY);
setPreserveEGLContextOnPause(true);
}
public void attachedToWindow(){
super.onAttachedToWindow();
}
public void detachedFromWindow(){
super.onDetachedFromWindow();
}
}
那么如何办呢?我们可以新建一个类GLEnvironment,将GLSurfaceView内容全部复制出来,然后取消其继承和接口实现,将所有报错的代码删除掉,这样就相当于剔除了GLSurfaceView的SurfaceView而保留了它的GL环境,我们可以使用GLEnvironment来进行渲染,并自由的指定渲染载体,可以是SurfaceView/TextureView或Pbuffer,也可以是Pixmap。
同样是利用setEGLWindowSurfaceFactory
方法来设置,当然可以改个名字更为贴切,比如setEGLSurfaceFactory,如下:
mEnv.setEGLSurfaceFactory(new GLEnvironment.EGLSurfaceFactory() {
@Override
public EGLSurface createSurface(EGL10 egl, EGLDisplay display, EGLConfig config, Object nativeWindow) {
/*使用SurfaceView或者TextureView,customWindow可以为SurfaceTexture\SurfaceHolder或者Surface等*/
egl.eglCreateWindowSurface(display,config,customWindow,null);
//使用pbuffer
//reture egl.eglCreatePbufferSurface();
//使用pixmap
//return egl.eglCreatePixmapSurface();
}
@Override
public void destroySurface(EGL10 egl, EGLDisplay display, EGLSurface surface) {
egl.eglDestroySurface(display,surface);
}
});
文章浏览阅读1.6k次。Android中视图动画使用率越来越少了,很多大神都使用属性动画了。但个人觉得视图动画比属性动画使用起来更简单,所以能用视图动画实现的就不考虑用属性动画。 今天在项目中使用视图动画时,遇到了几个坑,记录下来,供踩到同样坑的同学参考一下~一、平移与缩放冲突 使用视图动画,常使用到动画集合AnimationSet,然后在动画集合中添加平移、绽放,旋转等动画。_android view有动画时执行invisible
文章浏览阅读4.6w次,点赞102次,收藏897次。Anaconda使用教程一(新手友好)前言一、python和包以及anaconda的概念关系关于python与包关于anaconda二、Anaconda安装问题对windows三、Anaconda使用问题配置Anaconda源可能出现的错误conda install 仍然出现下载速度慢的错误四、Anaconda创建虚拟环境并使用创建你的第一个环境查看当前conda所有环境激活你的环境在你的环境中用conda或者pip安装包查看环境中现有的包在环境中运行python程序(windows系统)退出当前环境删除环_anaconda使用教程
文章浏览阅读1k次。题意:求在一定l时间内看完n中电影中的m是否可能,若可能则最后快乐度是多少。之前错了好多遍,一直找不到原因,后来在百度上看了很多别人的代码发现只有初始化不同我的初始化: memset(f,0,sizeof(f));别人的: for(int i=0;i for(int j=0;j一开始认为没什么影响,但是苦于一直找不到原因,所以我将自_hdu - 3496
文章浏览阅读2k次。下面可以不看,一句话,为了其安全起见,以后我们就用SecurityRandom就好了。JDK中有两个随机数类。一个是PRNG,也就伪随机数类java.util.Random,是采用线性同余算法产生的。另一个是RNG,也就是java.util.Random的子类强随机数java.security.SecureRandom,这是一个SPI类,也就是说具体的算法由Pro..._securerandom和math.random()
文章浏览阅读8k次,点赞8次,收藏8次。npm安装vue报错npm ERR! code ETIMEDOUT_code etimedout
文章浏览阅读5k次。这两天用阿里云服务器重新部署网站服务器后,打开某php页面出现了如下警告:Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50547 Library:50631 in /XXX(某某目录)/wp-db.php on line 1520,虽然是警告,但是有的界面会因此打不开,无法..._mysql headers:50647
文章浏览阅读97次。基于verilog驱动M25P16(FLASH) -------- SPI简介_m25p16 verilog sim model
文章浏览阅读23次。新建hyperv.bat,输入以下内容。管理员运行bat即可。
文章浏览阅读4.9w次。背景前两天写了一篇文章 OSX MAMP 如何为 PHP 5.6 安装 MSSQL 扩展,讲的是自己的个人电脑,也就是开发环境如何为 PHP 5.6 安装 MSSQL 扩展,现在要上生产了,继续讲讲怎么给 CentOS7 安装 PHP - MSSQL 扩展。运行环境操作系统CentOS Linux release 7.8.2003 (Core)集成环境宝塔PHP 5.6.40步骤和之前一样,我们先来整理一下整体的步骤:1、安装 freetds2、安装 mssql.so 扩展(p_宝塔面板centos7/php5.6安装mssql扩展
文章浏览阅读147次。这是交易 . 在我的Android应用程序中,我正在使用Jsoup进行一些网络抓取 . 现在它工作正常,但它太慢了 . 我在我的代码中做的是:通过Jsoup中的POST方法登录页面;获取cookie;通过重用cookie,我将浏览6页(POST和GET)并抓取它们(主要是表格和大量行 . 我的意思是很多......所以,真的很多foreach循环);将所有必需的数据写入SQLiteDatabase..._jsoup速度太慢
文章浏览阅读2.6k次。湖仓方案DeltaLake、Hudi、Iceberg功能对比_星环胡仓一体和hudi对比
文章浏览阅读3.7k次。编译 OpenCV打开终端进行编译:(-j 是使用 8 个线程进行编译,请根据你的计算机配置合理设置线程数)E:cd E:\opencv_341\opencv_mingw64_buildmingw32-make -j 8mingw32-make install如果 mingw32-make -j 8遇到错误,请看下面的 编译 OpenCV 常见错误,否则执行 mingw32-make..._m_pi' was not declared in this scope