8

I got the following problem , i made a form with a gallery, the gallery instead of containing images contains items from one of my classes, everything inside each item of the gallery displays perfectly. I removed the space between images using:

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
        <Gallery android:id="@+id/galleryid"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:spacing="0dip"
                android:padding="0dip"
                android:layout_weight="1" />

the items of the gallery:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="75dip" xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_horizontal" android:background="#ffffff"> 

    <TextView android:id="@+id/frame_number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="-" android:textSize="12dip" android:textColor="#ffffff" android:background="#000000" android:gravity="center" />
    <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" android:orientation="horizontal" android:gravity="center_horizontal">
                <TextView  android:id="@+id/frame_shot1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:textSize="18dip" android:textColor="#000000" />
                <TextView  android:id="@+id/frame_shot2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:textSize="18dip" android:textColor="#000000" />
    </LinearLayout> 
    <TextView android:id="@+id/frame_total" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="---" android:textSize="38dip" android:textColor="#000000"/>
</LinearLayout>

buuuuuuuuuuuuuuuuut , i got a problem, there is some blank space at the beginning and end of the gallery with no items. the thing is that my gallery has many items on it that u can actually scroll horizontally, but i wanna get rid of those spaces so the very first thing on the very left of the gallery is the first item, and the very last when u scroll to the very right is the right item.


Edit 08/16 Still with the same problem back in the project, here i leave an image of exactly what is what I'm trying to get rid of that is the black space at the beginning (also is at the end of the gallery at the other side)

enter image description here

Ale K.
  • 316
  • 6
  • 18

6 Answers6

2

The reason you get the blank space on the left is simply because there are no more items to display to the left of the first item (centred in the view). I would assume that the same problem arises to the right of the last item as well.

To properly solve this one will have to decide on what to display when there are no more items, but I will give some ideas:

(1) Increasing the width of the gallery items to the same width as the gallery will only show one item at a time, thus the user will never be able to scroll to the empty space.

(2) To display a solid color or an image in the blank space I would assume setting the android:background attribute of the gallery.

(3) Create a buffer in the beginning and end of your adapter, consisting of the last/first items respectively, and when the user scrolls far enough in the buffer, jump to the matching item at the other end of the gallery for a infinite "carousel" gallery.

Jave
  • 31,598
  • 14
  • 77
  • 90
  • Those are all no options that would not work for me. Currently I'm just using a HorizontalScrollView and add the items dynamically to just not have the space on the sides. – Maria Neumayer Dec 06 '11 at 16:20
  • If the selected gallery item is not important, you can override the fling and touch methods in a gallery extension and prevent scrolling to the end items. (if selectedPosition < 2 && trying to scroll left: return; if selectedposition > items-2 && trying to scroll right: return;) – Jave Dec 06 '11 at 18:08
  • I think with a bit of tweaking of all that I could get to a solution that could work. It's still not ideal, but better than anything else. – Maria Neumayer Dec 07 '11 at 10:06
  • True, depending on your needs you might be best of by just implementing your own horizontal list. After all, that might be more convenient than modifying the gallery. – Jave Dec 07 '11 at 10:36
2

Try:

int position=1;

void android.widget.AbsSpinner.setSelection(int position)
Barry Kaye
  • 7,682
  • 6
  • 42
  • 64
M.Salomaa
  • 63
  • 7
1

One thing you can try is to check if there's more than one item. If there is, set the selection on the gallery to be the second item.

Tim
  • 11
  • 1
0

set the margin of the gallery to -(metrics.widthPixels)+itemWidth, the blank space is hide.

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
params.setMargins(-(metrics.widthPixels)+itemWidth,0,0,0); 
gallery.setLayoutParams(params);
dreamcrash
  • 47,137
  • 25
  • 94
  • 117
0

Your probably talking about the fading edge length.

http://developer.android.com/reference/android/view/View.html#setFadingEdgeLength(int)

Try

setFadingEdgeLength(0);

Or

 setHorizontalFadingEdgeEnabled(false);

Try changing your layout for the gallery width to fill parent as well instead of wrap content:

   <Gallery android:id="@+id/galleryid"
            android:layout_width="fill_parent" 
Chris Lucian
  • 1,013
  • 6
  • 15
  • Sorry for the delay on answering chris, but nope, that is not the space i think i'm talking about, i got a gallery that fills the whole width of the screen with items... but anyways i got a blank space i can scroll trough on the left and on the right of the last and first item and i wanna get rid of it, like a space before the beginning and before the end... i want that out. Thanks. – Ale K. Jul 23 '11 at 17:30
  • Can you post all the xml to your view? Maybe a parents setting is effecting it? – Chris Lucian Jul 25 '11 at 18:36
  • Sorry, for the delay, here is the image and the whole code for the gallery activity and for my custom items – Ale K. Aug 16 '11 at 04:12
  • Change the layout_width to fill_parent. Also try setting gravity to left. This may push everything to one side. – Chris Lucian Aug 16 '11 at 15:30
  • Nop, didn't work :( what you see in the Image is the first 3 Frames of a scorekeeper for bowling, also when i scroll the gallery to the very right side, i got the same exact space. I even try to add a fixed value for the width, and didn't do it either. – Ale K. Aug 16 '11 at 16:00
  • I'm also trying to remove the leading and trailing space in a Gallery view with no success. I've tried the things mentioned in this answer but they didn't work. The Gallery view could be really useful if more customizable... – r1k0 Sep 13 '11 at 09:50
-2

I've just spent with this issue 2 hours and finally found a solution for myself. I have a Gallery, with custom LinearLayout elements. I want to display just 1 element a time without any padding on the start nor on the end.

After many tries I found that, if I set the minWidth parameter of every Item to a big number (android:minWidth="1000dp") my problem is solved. Don't know if it is suitable for your issue. Good Luck

Peter B.

peter.bartos
  • 11,855
  • 3
  • 51
  • 62
  • Nop, it didn't work for me, i updated my original post with an image of what it actually my problem looks like, anyways thanks for your help, any other ideas? – Ale K. Aug 16 '11 at 04:07