Android 开始和结束时的画廊空间

Android 开始和结束时的画廊空间,android,gallery,horizontal-scrolling,Android,Gallery,Horizontal Scrolling,我遇到了以下问题,我用一个图库制作了一个表单,图库中没有包含图片,而是包含我的一个类中的项目,每个项目中的所有内容都能完美地显示出来。我使用以下方法删除了图像之间的空间: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> &

我遇到了以下问题,我用一个图库制作了一个表单,图库中没有包含图片,而是包含我的一个类中的项目,每个项目中的所有内容都能完美地显示出来。我使用以下方法删除了图像之间的空间:

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

展览馆的项目包括:

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

Buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。问题是,我的图库中有很多项目,你可以水平滚动,但我想去掉这些空间,所以图库最左边的第一个项目是第一个项目,最后一个你滚动到最右边的项目是右边的项目


编辑08/16仍然在项目中遇到同样的问题,在这里我留下了一张我正试图摆脱的图像,这是开始时的黑色空间(也在另一边的画廊的末尾)


您可能在谈论衰减边长度

)

试一试

尝试更改库宽度的布局以填充父级,而不是包裹内容:

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

我刚刚花了两个小时研究这个问题,终于为自己找到了一个解决方案。我有一个画廊,带有定制的线性布局元素。我希望一次只显示一个元素,并且在开始和结束时都没有任何填充

经过多次尝试,我发现,如果我将每个项目的minWidth参数设置为一个大数字(android:minWidth=“1000dp”),我的问题就解决了。不知道它是否适合您的问题。祝你好运


Peter B.

您可以尝试的一件事是检查是否有多个项目。如果存在,将图库上的选择设置为第二项。

< P>左侧获取空白的原因仅仅是因为没有更多的项目显示在第一个项目的左侧(以视图为中心)。我假设最后一项的右边也会出现同样的问题

要正确解决此问题,必须决定在没有更多项目时显示什么,但我将给出一些想法:

(1) 将图库项目的宽度增加到与图库相同的宽度,一次只能显示一个项目,因此用户将永远无法滚动到空白区域

< P>(2)在空白空间中显示一个纯色或一个图像,我假设设置画廊的Android:背景属性。 (3) 在适配器的开头和结尾创建一个缓冲区,分别由最后一个/第一个项目组成,当用户在缓冲区中滚动足够远时,跳转到库另一端的匹配项目,创建一个无限“旋转木马”库。

尝试:

int position=1;

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

将库的边距设置为<代码> -(度量。宽度像素)+项目宽度>代码>,空白空间为隐藏。< /P>

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

抱歉耽搁了chris的回答,但不,这不是我想说的空间,我有一个画廊,整个屏幕都是项目。。。但不管怎样,我得到了一个空白,我可以在最后一个和第一个项目的左边和右边滚动,我想摆脱它,就像在开始和结束之前的空白。。。我想把它弄出来。谢谢。你能把所有的xml发布到你的视图中吗?可能是家长设置影响了它?抱歉,耽搁了,这是图片和画廊活动的全部代码,以及我的自定义项目更改布局宽度以填充家长。同时尝试将重力设置为左侧。这可能会把一切都推到一边。不,不起作用:(你在图片中看到的是保龄球记分员的前3帧,当我将图库滚动到最右侧时,我得到了相同的精确空间。我甚至尝试为宽度添加一个固定值,但也没有这样做。不,这对我不起作用,我用一个图片更新了我的原始帖子,它实际上是我的问题的样子,有没有方式感谢您的帮助,还有其他想法吗?这些都是对我不起作用的选项。目前我只是使用水平滚动视图,动态添加项目,以避免在侧面留有空间。如果选定的库项目不重要,您可以覆盖库扩展中的fling和touch方法,并防止滚动g到结束项。(如果选择位置<2&尝试向左滚动:返回;如果选择位置>项-2&尝试向右滚动:返回;)我想只要稍作调整,我就能找到一个可行的解决方案。它仍然不理想,但比其他任何东西都好。没错,根据你的需要,你最好只实现自己的水平列表。毕竟,这可能比修改库更方便。你找到解决方案了吗?你好,米娜你们找到这个问题的解决方案了吗?你好,SRam,Mina,和Ale k,你们找到上述问题的解决方案了吗?
int position=1;

void android.widget.AbsSpinner.setSelection(int position)
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
params.setMargins(-(metrics.widthPixels)+itemWidth,0,0,0); 
gallery.setLayoutParams(params);