0

I'm doing an Android gallery and I need to have the ImageView which shows a picture in full screen, and on top of it -meaning that it has to overlap the ImageView- the Gallery.

The problem is that now the ImageView occupies the portion that is not occupied by the Gallery, but I don't know how to achieve this.

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/GalleryImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:scaleType="fitXY" />

    <Gallery
        android:id="@+id/GalleryThumbnails"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/GalleryImage" />

</RelativeLayout>

Thanks a lot in advance!

noloman
  • 11,411
  • 20
  • 82
  • 129

1 Answers1

1

You can use layout_alignTop=[Reference] to achieve that effekt.

Makes the top edge of this view match the top edge of the given anchor view ID.

<ImageView
    android:id="@+id/GalleryImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:scaleType="fitXY" />

<Gallery
    android:id="@+id/GalleryThumbnails"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/GalleryImage" />

Proof that it works

enter image description here

Renard
  • 6,909
  • 2
  • 27
  • 23
  • in the Gallery to match the ImageView, or in the ImageView to match the root RelativeLayout? – noloman Apr 16 '12 at 13:18
  • The example should place the gallery on top of the ImageView. – Renard Apr 16 '12 at 13:36
  • what I wanna do is to put the ImageView OVER the Gallery, meaning that when the Gallery is there, it will be on top of the ImageView, and there'll be a portion (the bottom portion) of the ImageView that won't be visible,but after 5 seconds, the ImageView will be visible as the Gallery will disappear. – noloman Apr 16 '12 at 14:00
  • yes this is what the code does. It will make the Gallery overlap the ImageView. The top edge of the Gallery is aligned with the top edge if the imageview. Use android:layout_alignBottom to have the Gallery overlap the bottom part of the ImageView. – Renard Apr 16 '12 at 14:06
  • it simply doesn't work, as the ImageView completely overlaps the thumbnails gallery.. – noloman Apr 16 '12 at 14:16
  • Since the Gallery comes below the ImageView in my xml the Gallery should definitely overlap the ImageView and not the other way around. – Renard Apr 16 '12 at 14:36
  • added screenshot to show that it should work. There must be something else in your code.. – Renard Apr 16 '12 at 15:46
  • @Renard's code looks pretty solid, I have to agree with him. Must be something else you're doing. – breadbin Apr 16 '12 at 15:57
  • maybe it could be cus the gallery viewer can only be in landscape mode? – noloman Apr 17 '12 at 07:20
  • i don't think so. My Screenshot is in portrait mode :-) – Renard Apr 17 '12 at 07:35