I have a project on going and I am suppose to place Admob ads on canvas in android. Is it possible to place Admob ads on Canvas in Android.
You can place your canvas holding view in a FrameLayout and a admob AdView on top of it like
<FrameLayout>
<CanvasView/>
<AdView/>
</FrameLayout>
Also if your view is sophisticated and you don't want major performance impact you can draw it in a separate window layer. See my answer here.
Related
I have three weeks into Android development (newbie). Is it possible to draw a mask over a webview so that the webview looks like its a circle? My webview is showing google map (dragable). I want that map in the app to look like its a circle, instead of a rectangle that is filling the entire Layout.
In general, yes. But your webview will be unaware of the mask, so you might run into problems with the mask covering parts of the UI. I don't know about the Google Maps web API, but the Android API lets you set padding to move the controls and Google logo away from the edges.
You can create a custom View in which onDraw(Canvas) instructs some other View to draw into a bitmap, then applies a mask to the bitmap and draws it on the output Canvas. To make your webview appear circular, you'd place the custom view on top of the webview, and configure the custom view to use the view below the webview for drawing. This would create the appearance of a hole through the webview.
Shameless plug: I published a MaskView that does exactly this.
Alright, so the concept seems simple enough, but Have searched all over the web and have yet to find a solution. So I am making my first android game, woot. But I want to monetize it with ads. This is where the problem comes in. As I am Not using a layout for my game, but instead a GLSurfaceView, I cannot find anything about setting an ad over that. Every ad tutorial by google uses either a layout, or requires you to create a layout through java. The problem is, that those all still use a SurfaceView, not a GLSurfaceView. How can I implement an ad over the GLSurfaceView? I mean, most games, logically would be made using openGL, not canvas, so there would have to be a way, right?
Any suggestions will help. If you guys need to see some of the code, let me know, but it's pretty standard code from the glSurfaceView Tutorials.
GLSurfaceView is just a SurfaceView with some code wrapped around it to manage threads and the EGL context. They're not very different.
SurfaceView has two parts, the "surface" and the "view". The view is part of the View hierarchy, and is generally just a transparent window used for the layout. All of the View-based UI is drawn on a single layer. GLES rendering is done on the surface part, which is a separate layer composited by the system. By default, the surface layer sits behind the view layer, but you can configure that when the SurfaceView is created.
Since the Surface is behind the View, you can draw your ads with Views on top of your game without interfering with it.
You can find some examples in Grafika. For example, the "record GL app" activity has UI elements (some text and radio buttons) on top of GLES animation. It uses a relative layout and positions the UI elements on top of the SurfaceView.
According to this manual, you can test the code blow:
TextView textView = new TextView(this);
textView.setText("overlay!");
addContentView(textView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Obviously, the code is in the Activity.
So I did much researching and finally found a solution that works, thanks to fadden for getting me on the right track btw :)
mGLView = new MyGLSurfaceView(this);
LinearLayout screenLayout = new LinearLayout(this);
screenLayout.setOrientation(LinearLayout.VERTICAL);
// Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("/6499/example/banner");
AdRequest.Builder adRequest= new AdRequest.Builder();
adView.loadAd(adRequest.build());
screenLayout.addView(adView);
screenLayout.addView(mGLView);
setContentView(screenLayout);
I'm making sort of a drawing program and using admob to get some earnings :)
So what I want is when the user draw a line over the AdView it renders over it and not under. Is it possible or complete crazyness?
this is likely against the Admob TOS: http://support.google.com/admob/answer/1307237?hl=en
". Ads should not be placed in areas where users will randomly click or place their fingers on the screen."
...i know as ad advertiser, i would not want anything covering my ads
I was using XML to create layouts for my application but recently I found that layouts can also be created with the help of canvas using surface View so I wanted to know whether it is advisable to create a layout with the help of canvas or not?
You can use Canvas to draw things on it, like lines, circle, text and bitmaps. However you can not add Widgets to it.
So yes, you could use Canvas to create Ui, but you would have to do everything from scratch, basically reimplement needed Widgets. This is what games usually do, but its impractical for "normal" projects, especially if you need complex Widgets like ListView.
In Android 2.2, I want to display a few sprites and clickable animations over an existing view. I just discovered that SurfaceView cannot be transparent
I tried overriding dispatchDraw() of a LinearLayout but that doesn't seem to be callable via a Runnable Thread.
I also tried to extend Canvas directly, but that quickly turned into a mess when trying to place it in my XML layout.
Do I have to use GLSurfaceView to have a drawing view whose background is transparent?
Optimally, I'd like to just have a Canvas on which I can draw Bitmap at various coordinates, instead of dealing with the details of GL (unless GL is the only way I can do transparency).
Silly Rabbit. Just use Views and move them around wherever you want within a FrameLayout. SurfaceView is not designed for what you're trying to do.
I'm going to try Switching from Canvas to OpenGL and toss in parts of TranslucentGLSurfaceView.
I'm still open to selecting an answer that doesn't require OpenGL, just for the sake of it solving my original question.