Gallery space at beginning and end

限于喜欢 提交于 2019-12-05 03:01:40

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.

M.Salomaa

Try:

int position=1;

void android.widget.AbsSpinner.setSelection(int position)

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.

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" 
keven wu

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!