question

Denis Lapiner avatar image
Denis Lapiner asked

AdLayout alignment/gravity

I'm integrating Amazon Ads into an existing Unity project. I'm using a .jar file for this, which works for AdMob, but unfortunately my setup does not allow to use .xml layout files yet. Is there a way to tell the AdLayout that it has to be on top right programmatically? What I try is: 1. create a layout: LinearLayout layout = new LinearLayout(UnityPlayer.currentActivity.getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.RIGHT); LinearLayout.LayoutParams layoutParam = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); UnityPlayer.currentActivity.addContentView(layout, layoutParam); 2. create ad layout: s_amazonView = new AdLayout(UnityPlayer.currentActivity, com.amazon.device.ads.AdSize.SIZE_320x50); s_amazonView.setListener(...); 3. add the ad layout to layout: FrameLayout.LayoutParams amazonViewParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT); layout.addView(s_amazonView, amazonViewParams); I have tried every possible combination of layouts gravities and alignment rules, but the ad is always centered at the top of the screen... Any ideas anyone? Message was edited by: freebordmad
mobile ads
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Denis Lapiner avatar image
Denis Lapiner answered
found the problem... the AdLayout always takes the size of the screen as width if there is no certain value, so I had to set layout_width of it to 320dp. Also the wraping layouts like used in Amazon's examples are not needed, since AdLayout is a FrameLayout itself. Here the code: // Create the adView s_amazonView = new AdLayout(UnityPlayer.currentActivity, com.amazon.device.ads.AdSize.SIZE_320x50); s_amazonView.setListener(...); // Add the adView to layout FrameLayout.LayoutParams amazonViewParams = new FrameLayout.LayoutParams( (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 320, UnityPlayer.currentActivity.getResources().getDisplayMetrics()), LinearLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT); UnityPlayer.currentActivity.addContentView(s_amazonView, amazonViewParams);
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Denis Lapiner avatar image
Denis Lapiner answered
see last post
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Freebordmad Thanks for posting and sharing the experience with us. This would help the other unity developers.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.