Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

How to make an Android Processing sketch fragment semi-transparent

$
0
0

Hi all!

I'm happily using Processing from the Android IDE, allowing me to add certain critical functionality through Android Java directly. For the project I'm now working on, I want to overlay all kinds of nice Processing sketches, in a "virtual reality" way, over a camera view. Because displaying the camera view and doing the required detection is a bit heavy, I'll be doing this with OpenCV instead of Processing. My idea was to then simply overlay the Processing sketch fragment over the OpenCV fragment, thus allowing the cool 3D stuff to be easily programmed in Processing, while the more intensive camera stuff is done with OpenCV.

However, although I've managed to make simple Android fragments semi-transparent, I can't seem to be able to make the Processing sketch fragment semi-transparent. Maybe this is because it's neccessary to go all the way down to the SurfaceView involved and make it semi-transparent or something?

I'd be very much obliged if someone could help me out :)

The code is generally as follows:

The main layout file:

<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" ... > <FrameLayout android:id="@+id/bg_frame" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#cc0000" ... > <FrameLayout android:id="@+id/fg_frame" android:layout_width="fill_parent" android:layout_height="fill_parent" ... > </RelativeLayout>

The Processing sketch:

public class MySketch extends PApplet { ... public void draw() { background(color(255, 50)); // semi-transparent ... } ... }

The activity:

public class MainActivity extends Activity { ... protected void onCreate(Bundle savedInstanceState) { ... getFragmentManager().beginTransaction() .add(R.id.fg_frame, new MySketch()) .commit(); ... } ... }

I have tried (as you can see above) using Processing's background color background(color(255, 50)).

Also, I've tried setting android:background="@android:color/transparent" as well as android:alpha="0.5f" in the fb_frame frame layout.


Viewing all articles
Browse latest Browse all 941

Trending Articles