こんにちは、アプリケーションの 1 つで MMAdView を使用しています。SAMSUNG S3 を除くすべてのデバイスで正常に動作しています。なぜこれが起こるのか、この問題について何か考えがあります。
ここに付属のスクリーンショート
この 480x800 Htc デバイス
そしてここに Samsung s3 デバイス 720x1280
IN samsung s3 デバイスの右側隅にある空白。
これは私が使用しているコードです。
活動コード
public class MainActivity extends Activity {
private static final int MED_BANNER_WIDTH = 480;
private static final int MED_BANNER_HEIGHT = 60;
//Constants for phone sized ads (320x50)
private static final int BANNER_AD_WIDTH = 320;
private static final int BANNER_AD_HEIGHT = 50;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("MainActivity", "one");
int placementWidth = BANNER_AD_WIDTH;
int placementHeight = BANNER_AD_HEIGHT;
//Finds an ad that best fits a users device.
if(canFit(BANNER_AD_WIDTH)) {
Log.i("MainActivity", "two");
placementWidth = BANNER_AD_WIDTH;
placementHeight = BANNER_AD_HEIGHT;
} else if(canFit(MED_BANNER_WIDTH)) {
Log.i("MainActivity", "three");
placementWidth = MED_BANNER_WIDTH;
placementHeight = MED_BANNER_HEIGHT;
}
MMAdView adView = new MMAdView(this);
adView.setApid("Appid");
MMRequest request = new MMRequest();
adView.setMMRequest(request);
adView.setId(MMSDK.getDefaultAdId());
adView.setWidth(placementWidth);
adView.setHeight(placementHeight);
//Calculate the size of the adView based on the ad size. Replace the width and height values if needed.
int layoutWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, placementWidth, getResources().getDisplayMetrics());
int layoutHeight = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, placementHeight, getResources().getDisplayMetrics());
//Create the layout parameters using the calculated adView width and height.
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(layoutWidth, layoutHeight);
//This positions the banner.
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
adView.setLayoutParams(layoutParams);
adView.getAd();
Log.i("MainActivity", "four");
RelativeLayout layout = (RelativeLayout) findViewById(R.id.adBannerRelativeLayout);
//Add the adView to the layout. The layout is assumed to be a RelativeLayout.
layout.addView(adView);
}
protected boolean canFit(int adWidth) {
Log.i("MainActivity", "five");
int adWidthPx = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
adWidth, getResources().getDisplayMetrics());
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
Log.i("MainActivity", " metrics==> "+ metrics);
return metrics.widthPixels >= adWidthPx;
}
}
これは Xml ファイルです
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mm="http://millennialmedia.com/android/schema"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/adBannerRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
EDIT:
これは私がMMAdViewを使用しているドキュメントです