[英]how to make surfaceview transparent
大家好我想让我的DrawingSurface视图透明。 我试了很多东西,但它不起作用。
这是我的表面视图透明的xml代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/icon" >
</ImageView>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000" >
<codewalla.android.drawings.DrawingSurface
android:id="@+id/drawingSurface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</codewalla.android.drawings.DrawingSurface>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/colorRedBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="R" />
<Button
android:id="@+id/colorBlueBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="G" />
<Button
android:id="@+id/colorGreenBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="B" />
<Button
android:id="@+id/undoBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="U" />
<Button
android:id="@+id/redoBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="R" />
</LinearLayout>
</RelativeLayout>
在构造函数中尝试这个:
SurfaceView sfvTrack = (SurfaceView)findViewById(R.id.sfvTrack);
sfvTrack.setZOrderOnTop(true); // necessary
SurfaceHolder sfhTrackHolder = sfvTrack.getHolder();
sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT);
sfvTrack.setZOrderOnTop(true);
将surfaceView放在窗口顶部,这意味着您无法在surfaceView顶部添加项目。
如果要在曲面视图的顶部添加视图; 你应该考虑使用:
setZOrderMediaOverlay(true);
代替。 这会将此surfaceView放在其他surfaceViews的顶部,但仍然在窗口后面,允许您在曲面视图的顶部添加其他可见视图。
我相信TexttureView
会比SurfaceView
更好地满足您的需求。
是您的DrawingSurface和SurfaceView的扩展吗?
无法让SurfaceView执行您希望它执行的操作。 表面视图的机制使得它后面不能有任何可见的东西。 (请参阅http://groups.google.com/group/android-developers/browse_thread/thread/8d88ef9bb22da574上的答案)
我使用扩展SurfaceView的自定义视图测试了您的层次结构,我看到了您的问题。 如果我切换到只扩展View的自定义视图,我可以获得透明度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.