Gallery area at the beginning and end

I had the following problem: I made a form with a gallery, instead of images the gallery contains elements from one of my classes, everything inside each gallery element is perfectly displayed. I removed the space between the 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" /> 

gallery elements:

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

buuuuuuuuuuuuuuuutu, I have a problem, there is an empty space at the beginning and at the end of the gallery without elements. the fact is that in my gallery there are many objects that can really scroll horizontally, but I want to get rid of these spaces, so the very first thing that is to the left of the gallery is the first element, and the very last when you scroll to the right is the correct element.


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

enter image description here

+8
android gallery horizontal-scrolling
source share
6 answers

The reason you get empty space on the left is simply because there are no more elements to display to the left of the first element (centered in the view). I would suggest that the same problem occurs to the right of the last element.

In order to solve this problem correctly, you will need to decide what to show when there are no more items, but I will give a few ideas:

(1) Increasing the width of gallery elements to the same width as in the gallery will only display one element at a time, so the user will never be able to scroll to empty space.

(2) To display a solid color or image in empty space, I would assume to set the android: background attribute in the gallery.

(3) Create a buffer at the beginning and end of your adapter, consisting of the last / first elements, respectively, and when the user scrolls far enough in the buffer, go to the corresponding element on the other end of the gallery for the endless gallery "Carousel".

+2
source share

Try:

 int position=1; void android.widget.AbsSpinner.setSelection(int position) 
+2
source share

One thing you can try is to check if there are more than one item. If there is, set the gallery as the second item in the gallery.

+1
source share

You are probably talking about the length of the fading edge.

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

Try

 setFadingEdgeLength(0); 

or

  setHorizontalFadingEdgeEnabled(false); 

Try changing the layout for the width of the gallery to fill the parent object rather than wrapping the contents:

  <Gallery android:id="@+id/galleryid" android:layout_width="fill_parent" 
0
source share

set the gallery field -(metrics.widthPixels)+itemWidth , the empty space will be hidden.

 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); params.setMargins(-(metrics.widthPixels)+itemWidth,0,0,0); gallery.setLayoutParams(params); 
0
source share

I just spent 2 hours with this problem and finally found a solution for myself. I have a Gallery with custom LinearLayout elements. I want to display only 1 time element without any additions at the beginning or at the end.

After many attempts, I found that if I set the minWidth parameter for each element to a large number (android: minWidth = "1000dp"), my problem will be solved. I don’t know if it is suitable for your problem. Good luck

Peter B.

-2
source share

All Articles