我的智能横幅广告正在运行,但我希望它显示在我应用的底部而不是当前的顶部 - 最好是使用java。
Main.java
public class MainActivity extends Activity {
private AdView adView;
private static final String AD_UNIT_ID = "unique_id_here";
private ImageView mPlayPic;
MediaPlayer mRainSound;
private ImageView mBgImg;
private ImageView mNextPicButton;
private int currentImage = 0;
int[] images = { R.drawable.pic4, R.drawable.pic1, R.drawable.pic5, R.drawable.pic8, R.drawable.rsz_1pic9, R.drawable.rsz_pic7 };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_rain);
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
RelativeLayout layout = (RelativeLayout) findViewById(R.id.relativeLayout);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("0C179D00E6B9B79C492DCCA6A64B1FA9") //gotten from running as Debug and reading logcat
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/bgImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:src="@drawable/pic4"
android:scaleType="fitXY" />
<ImageView
android:id="@+id/picImage"
android:layout_width="110dp"
android:layout_height="110dp"
android:padding="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:contentDescription="@null"
android:src="@drawable/opaq_mountain" />
<ImageView
android:id="@+id/playImage"
android:layout_width="110dp"
android:layout_height="110dp"
android:padding="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:contentDescription="@null"
android:src="@drawable/square_play_opac" />
</RelativeLayout>
感谢我能得到的任何帮助,谢谢!
答案 0 :(得分:2)
为您的广告设置以下RelativeLayout.LayoutParams
:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) adView.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
adView.setLayoutParams(params);
在layout.addView(adView);
答案 1 :(得分:0)
在你的相对布局内的另一个线性布局。将android:layout_gravity设置为此线性布局的底部,并将您的adview添加到此线性布局。为我工作。