ventsi.slav
ventsi.slav

Reputation: 332

How to fix that layout in android

Pretty new on android and java.

A simple question here for you.

My application is very simple. I have a gallery of images showing to the user. When he clicks the image,a new one is loading. I have and an admob at the bottom.

However I cant position them as I need. The admob at the moment is not showing and returning error that there`s not enough space in the width. I want to fit the image from end to end of the screen. At the moment the images are with big black border from every side.

Here`s my activity:

<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>

Upvotes: 0

Views: 147

Answers (3)

PX Developer
PX Developer

Reputation: 8145

If you want the ImageView to take all the available space over the Ad use this code:

<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

This way your ImageView will always be above Ad.

If you want to use Stephane's solution you will need to change your RelativeLayout to LinearLayout.

Upvotes: 0

Stephane Mathis
Stephane Mathis

Reputation: 6622

Change the SmartImageView for a height of 0dp and a layout_weight="1". This View will take all the place available and let the Ad request its own height.

Upvotes: 1

Tom Fobear
Tom Fobear

Reputation: 6749

You have the height of the SmartImageView set to match_parent, which leaves no room for the AdView

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

Upvotes: 0

Related Questions