Android Ads无法正确显示,activity_main.xml
在LinearLayout中,当我将其更改为RelativeLayout时,我的adds无法显示,因为没有足够的广告空间,但我保留在顶部的按钮消失了。请帮帮我。而且,如果可能的话,我想把我的add放在底部。谢谢Android Ads无法正确显示,activity_main.xml,android,xml,android-layout,android-studio,Android,Xml,Android Layout,Android Studio,在LinearLayout中,当我将其更改为RelativeLayout时,我的adds无法显示,因为没有足够的广告空间,但我保留在顶部的按钮消失了。请帮帮我。而且,如果可能的话,我想把我的add放在底部。谢谢 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://sch
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="25"
android:onClick="gotoPreviousImage"
android:padding="10dip"
android:text="<" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="50"
android:onClick="setAsWallpaper"
android:padding="10dip"
android:text="Set as Background" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="25"
android:onClick="gotoNextImage"
android:padding="10dip"
android:text=">" />
</LinearLayout>
<ImageView
android:id="@+id/backgroundPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="Preview of the wallpaper to choose"
android:scaleType="fitXY" />
<com.google.android.gms.ads.AdView
android:id="@+id/AdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="Unit_ID"
ads:adSize="SMART_BANNER"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
/>
</LinearLayout>
尝试以下方法:使用framelayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout android:layout_gravity="top"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="25"
android:onClick="gotoPreviousImage"
android:padding="10dip"
android:text="<" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="50"
android:onClick="setAsWallpaper"
android:padding="10dip"
android:text="Set as Background" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="25"
android:onClick="gotoNextImage"
android:padding="10dip"
android:text=">" />
</LinearLayout>
<ImageView
android:id="@+id/backgroundPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="Preview of the wallpaper to choose"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<com.google.android.gms.ads.AdView
android:id="@+id/AdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="bottom"
ads:adSize="SMART_BANNER"
ads:adUnitId="Unit_ID" />
</FrameLayout>
让我知道它是否有效//用xml代码替换此代码并重播我
//Replace this code with your xml code and replay me
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="25"
android:onClick="gotoPreviousImage"
android:padding="10dip"
android:text="<" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="50"
android:onClick="setAsWallpaper"
android:padding="10dip"
android:text="Set as Background" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="25"
android:onClick="gotoNextImage"
android:padding="10dip"
android:text=">" />
</LinearLayout>
<ImageView
android:id="@+id/backgroundPreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="Preview of the wallpaper to choose"
android:scaleType="fitXY" />
</LinearLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/AdView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="Unit_ID"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
尝试为单个子组件指定布局权重等权重。您如何显示此图像视图?我猜这张照片的高度和宽度都很高。因此,请尝试将其移除一段时间,看看其他功能是否正常。@vo12不工作:(仍然是相同的错误“没有足够的空间显示广告。需要360x50 dp,但只有360x0 dp。”都德,你们已经把垂直方向放在第一个子线性布局、图像视图和adview上,然后做高度0px@SeijiDinzuala给Imageview高度换行谢谢,但这三个按钮仍然不可见,或者它们位于Imageview后面,与RelativeLayout中的相同:(在我的情况下看起来很好..我编辑了答案,将重力放在第一个线性布局上。试试看LOL。仍然一样,还有其他想法吗?:D现在看起来怎么样。因为在我的情况下,它看起来很好,shw代码也很好。我很抱歉回复太晚,这是我认为我们需要缩放图片的图片?