问题
I'm working to implement a lock screen just like the water ripple lock screen of Samsung Galaxy 3. I have finished the GLSurfaceView object. But there is a problem when I port it to Lock Screen. The SurfaceView couldn't be displayed on Lock Screen whose window type is TYPE_KEYGUARD. If I use setZOrderOnTop(true) to this SurfaceView, it Can be displayed, but it will overlay all other layers of Lock Screen, which is not my anticipation. This SurfaceView can display normally on normal application. I used "adb shell dumpsys SurfaceFlinger" to dump the layers information. Its visibleRegionScreen is just as this, Region visibleRegionScreen (this=0x15841a0, count=1) [ 0, 0, 0, 0]
Anyone kown how to resolve this issue and display a SurfaceView on Lock Screen? Thanks a lot.
回答1:
You are right about the setZOrderOnTop(true) call but I don't really understand your question. You are only seeing the SurfaceView throughout the whole screen? In that case, just place a LinearLayout in the lock screen layout xml and add your Surfaceview to that.
In keyguard_screen_tab_unlock.xml after the digital clock view, put:
<LinearLayout
android:id="@+id/dummyGLLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top">
</LinearLayout>
In LockScreen.java constructor:
GLSurfaceView mySurfaceView
mySurfaceView = new MySurfaceViewClass(mContext);
LinearLayout ll = (LinearLayout) findViewById(R.id.dummyGLLayout);
mySurfaceView.setZOrderOnTop(true);
ll.addView(mySurfaceView);
回答2:
I'm appreciate for your comment. Attach my implemention for your referrence. The GLSurfaceView couldn't be shown on Lock screen. My Layout is as this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_lockscreen_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/my_lockscreen_clock"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:visibility="gone"/>
Add the GLSurfaceViewn on LockScreen.java constructor:
RelativeLayout mRootLayout = (RelativeLayout) findViewById(R.id.my_lockscreen_root);
View myGLSurfaceView = new MyGLSurfaceView(mContext, mCallback);
FrameLayout.LayoutParams layoutparams =
new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mRootLayout.addView(mUnlockWidget, 0, layoutparams);
来源:https://stackoverflow.com/questions/13797906/how-to-show-surfaceview-on-lock-screen