2013-06-12 80 views
0

在android和java上很新颖。如何在android中修复该布局

这是一个简单的问题给你。

我的申请很简单。 我有一个图片展示给用户的图像。 当他点击图片时,正在加载一个新图片。 我有和底部的admob。

但是我不能根据需要定位它们。 目前admob没有显示并返回错误,没有足够的空间宽度。 我想要适合屏幕从头到尾的图像。 目前图像的边缘都是黑色的大边框。

Here`s我的活动:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#000000" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"> 

<com.loopj.android.image.SmartImageView 
    android:id="@+id/image_switcher" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<com.google.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    app:adSize="SMART_BANNER" 
    app:adUnitId="738a44d913034b9f" > 

</com.google.ads.AdView> 

+0

我需要在图像上的admob,而不是在它们下面。 我刚刚从相关布局中删除了填充,现在可以了。 但是,admob只显示在模拟器上,而不是在真实设备上工作。 –

回答

0

你有SmartImageView设置为match_parent,不留下余地AdView

<com.loopj.android.image.SmartImageView 
android:id="@+id/image_switcher" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" /> 
1

更改为SmartImageView的高度0dp的高度和layout_weight =“1”。此视图将占用所有可用的位置,并让广告请求拥有自己的高度。

+0

为什么有人投我的答案? –

0

如果你想要的ImageView采取一切可用的空间,在广告中使用此代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"> 

    <com.loopj.android.image.SmartImageView 
     android:id="@+id/image_switcher" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/ad" /> 

    <com.google.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     app:adSize="SMART_BANNER" 
     app:adUnitId="738a44d913034b9f" > 

    </com.google.ads.AdView> 
</RelativeLayout 

这样你的ImageView永远是上面的广告。

如果您想使用Stephane的解决方案,您需要将您的RelativeLayout更改为LinearLayout。