Making Custom Android SurfaceView Transparent

Possible Duplicate:
how to make surfaceview transparent

I am trying to make a custom surface view semi translucent. Currently the activity is transparent so I can see the activity before it underneath, but as soon as I add my custom view that is 20dp * 20 dp (called ControlsOverlayView) it shows up as a black square on the screen. I have seen this post How to make a ListView transparent in Android? and have tried setting background color, cachehint and alpha of the view to no avail.

The transparent activity housing the view is ControlsOverlayActivity.java:

public class ControlsOverlayActivity extends Activity {

    private ControlsOverlayView overlay;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        TextView textView = (TextView) findViewById(R.id.test_text);
        try {
            textView.setText("test");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
    }
}

The test.xml layout including a sample TextView and my custom ControlsOverlayView is:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/test"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <TextView android:id="@+id/test_text"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

  <wp.ui.ControlsOverlayView
    android:layout_width="20dp"
    android:layout_height="20dp" 
    android:background="#00000000"
    android:cacheColorHint="#00000000"
    android:alpha="0"
    />

</FrameLayout>

and view:

public class ControlsOverlayView extends SurfaceView implements Runnable, Callback{

    public ControlsOverlayView(Context context, AttributeSet attrs) {
        super(context, attrs);

        // make sure we get key events
        setFocusable(true);
        setFocusableInTouchMode(true);
        requestFocus();

        // register our interest in hearing about changes to our surface
        getHolder().addCallback(this);
    }

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        //resize(getWidth(), getHeight());
        //paintControls();

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void run() {
        // TODO Auto-generated method stub

    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
    }

}

also in my manifest i have:

<activity android:name=".ui.ControlsOverlayActivity" android:theme="@style/Theme.Transparent">
        </activity>

and the Theme.Transparent is defined as:

<style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">false</item>
  </style>

Again it is just the custom view that can`t get to be transparent. Any ideas?


显然,因为你是从SurfaceView继承你不能获得透明度,请参阅StackOverflow答案制作SurfaceView透明

链接地址: http://www.djcxy.com/p/66770.html

上一篇: 在一切之上

下一篇: 使自定义Android SurfaceView透明