Richard R.
- Forum-Beiträge: 90
25.08.2011, 01:03:15 via Website
25.08.2011 01:03:15 via Website
Hi Leute,
wer schonmal Madvertise eingebunden hat, kennt das Problem: im Gegensatz zum Admob-Banner ist der Madvertise-Banner sehr klein, auch wenn er eigentlich genügend Platz haben sollte.
Das Problem liegt aber nicht am Banner, der skaliert korrekt, was man daran merkt, dass man auch auf den "leeren" Platz neben dem Banner klicken kann, um die Werbeseite aufzurufen.
Nein, das Problem liegt am Image, das angezeigt wird. Diese Bilder sind nur in der angezeigten Größe verfügbar und werden vom Madvertise-SDK standard-mäßig nicht hochskaliert. Das lässt sich ändern...
Wenn ihr das Madvertise-SDK im Eclipse eingebunden habt, öffnet die Datei StaticBannerView.java. Die müsste jetzt wie folgt aussehen:
In Zeile 30 sieht man, dass das Bitmap, welches das Werbe-Bildchen darstellt, einfach direkt in den View eingebunden wird. Um die volle Größe des Views aber auszunutzen, müssen wir es reskalieren. Hier ist der Code:
Hier nochmal das Ergebnis in Screenshots. Kleiner Werbebanner vorher (links), großer Werbebanner nachher (rechts).
Und hier die Original-Quelle in der ich den Code für das Bilder-Skalieren gefunden habe: http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
EDIT: Es scheint, dass View.getHeight() bzw. View.getWidth() (Zeilen 35 und 36 im Code oben) bei mir jeweils den Wert 0 haben, so dass ich diese dynamischen Werte nicht verwenden kann und statt dessen fixe Integer-Werte eintragen muss (Width = 480, Height = 75), was nicht gerade optimal ist. Wenn jemand eine Lösung, oder andere Verbesserungsvorschläge für den o.g. Code hat, bitte posten. Danke!
wer schonmal Madvertise eingebunden hat, kennt das Problem: im Gegensatz zum Admob-Banner ist der Madvertise-Banner sehr klein, auch wenn er eigentlich genügend Platz haben sollte.
Das Problem liegt aber nicht am Banner, der skaliert korrekt, was man daran merkt, dass man auch auf den "leeren" Platz neben dem Banner klicken kann, um die Werbeseite aufzurufen.
Nein, das Problem liegt am Image, das angezeigt wird. Diese Bilder sind nur in der angezeigten Größe verfügbar und werden vom Madvertise-SDK standard-mäßig nicht hochskaliert. Das lässt sich ändern...
Wenn ihr das Madvertise-SDK im Eclipse eingebunden habt, öffnet die Datei StaticBannerView.java. Die müsste jetzt wie folgt aussehen:
1/*
2 * Copyright 2011 madvertise Mobile Advertising GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package de.madvertise.android.sdk;
17
18import android.content.Context;
19import android.graphics.Bitmap;
20import android.widget.ImageView;
21
22/**
23 * Simple view to show a non animated ad.
24 */
25public class StaticBannerView extends ImageView {
26
27 public StaticBannerView(Context context, Bitmap bannerBitmap) {
28 super(context);
29 if (bannerBitmap != null) {
30 this.setImageBitmap(bannerBitmap);
31 }
32 }
33}
2 * Copyright 2011 madvertise Mobile Advertising GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package de.madvertise.android.sdk;
17
18import android.content.Context;
19import android.graphics.Bitmap;
20import android.widget.ImageView;
21
22/**
23 * Simple view to show a non animated ad.
24 */
25public class StaticBannerView extends ImageView {
26
27 public StaticBannerView(Context context, Bitmap bannerBitmap) {
28 super(context);
29 if (bannerBitmap != null) {
30 this.setImageBitmap(bannerBitmap);
31 }
32 }
33}
In Zeile 30 sieht man, dass das Bitmap, welches das Werbe-Bildchen darstellt, einfach direkt in den View eingebunden wird. Um die volle Größe des Views aber auszunutzen, müssen wir es reskalieren. Hier ist der Code:
1/*
2 * Copyright 2011 madvertise Mobile Advertising GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package de.madvertise.android.sdk;
17
18import android.content.Context;
19import android.graphics.Bitmap;
20import android.graphics.Matrix;
21import android.widget.ImageView;
22
23/**
24 * Simple view to show a non animated ad.
25 */
26public class StaticBannerView extends ImageView {
27
28 public StaticBannerView(Context context, Bitmap bannerBitmap) {
29 super(context);
30 if (bannerBitmap != null) {
31
32 int width = bannerBitmap.getWidth();
33 int height = bannerBitmap.getHeight();
34
35 int newWidth = this.getWidth();
36 int newHeight = this.getHeight();
37
38 // calculate the scale - in this case = 0.4f
39 float scaleWidth = ((float) newWidth) / width;
40 float scaleHeight = ((float) newHeight) / height;
41
42 // createa matrix for the manipulation
43 Matrix matrix = new Matrix();
44 // resize the bit map
45 matrix.postScale(scaleWidth, scaleHeight);
46
47 Bitmap resizedBitmap = Bitmap.createBitmap(bannerBitmap, 0, 0,
48 width, height, matrix, true);
49
50 this.setImageBitmap(resizedBitmap);
51 }
52 }
53}
2 * Copyright 2011 madvertise Mobile Advertising GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package de.madvertise.android.sdk;
17
18import android.content.Context;
19import android.graphics.Bitmap;
20import android.graphics.Matrix;
21import android.widget.ImageView;
22
23/**
24 * Simple view to show a non animated ad.
25 */
26public class StaticBannerView extends ImageView {
27
28 public StaticBannerView(Context context, Bitmap bannerBitmap) {
29 super(context);
30 if (bannerBitmap != null) {
31
32 int width = bannerBitmap.getWidth();
33 int height = bannerBitmap.getHeight();
34
35 int newWidth = this.getWidth();
36 int newHeight = this.getHeight();
37
38 // calculate the scale - in this case = 0.4f
39 float scaleWidth = ((float) newWidth) / width;
40 float scaleHeight = ((float) newHeight) / height;
41
42 // createa matrix for the manipulation
43 Matrix matrix = new Matrix();
44 // resize the bit map
45 matrix.postScale(scaleWidth, scaleHeight);
46
47 Bitmap resizedBitmap = Bitmap.createBitmap(bannerBitmap, 0, 0,
48 width, height, matrix, true);
49
50 this.setImageBitmap(resizedBitmap);
51 }
52 }
53}
Hier nochmal das Ergebnis in Screenshots. Kleiner Werbebanner vorher (links), großer Werbebanner nachher (rechts).
Und hier die Original-Quelle in der ich den Code für das Bilder-Skalieren gefunden habe: http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
EDIT: Es scheint, dass View.getHeight() bzw. View.getWidth() (Zeilen 35 und 36 im Code oben) bei mir jeweils den Wert 0 haben, so dass ich diese dynamischen Werte nicht verwenden kann und statt dessen fixe Integer-Werte eintragen muss (Width = 480, Height = 75), was nicht gerade optimal ist. Wenn jemand eine Lösung, oder andere Verbesserungsvorschläge für den o.g. Code hat, bitte posten. Danke!
— geändert am 25.08.2011, 13:52:55