【问题标题】:Gallery space at beginning and end开始和结束的画廊空间
【发布时间】:2011-10-08 19:13:09
【问题描述】:

我遇到了以下问题,我制作了一个带有画廊的表单,画廊而不是包含图像的包含来自我的一个班级的项目,画廊的每个项目内的所有内容都完美显示。我使用以下方法删除了图像之间的空间:

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

buuuuuuuuuuuuuuuuut ,我遇到了一个问题,画廊的开头和结尾有一些空白区域,没有任何项目。问题是我的画廊上有很多项目,你实际上可以水平滚动,但我想摆脱这些空间,所以画廊最左边的第一件事是第一个项目,当你滚动时最后一个项目最右边是正确的项目。


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

【问题讨论】:

  • 您找到解决方案了吗?
  • 你好 Mina 和 Ale k 你找到这个问题的解决方案了吗?
  • 您好 SRam、Mina 和 Ale K,您找到上述问题的解决方案了吗?

标签: android gallery horizontal-scrolling


【解决方案1】:

设置图库的边距为-(metrics.widthPixels)+itemWidth,空白处隐藏。

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

【讨论】:

    【解决方案2】:

    试试:

    int position=1;
    
    void android.widget.AbsSpinner.setSelection(int position)
    

    【讨论】:

      【解决方案3】:

      您在左侧获得空白区域的原因仅仅是因为在第一个项目的左侧(在视图中居中)没有更多的项目可以显示。我会假设最后一项的右侧也会出现同样的问题。

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

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

      (2) 为了在空白处显示纯色或图像,我假设设置了画廊的 android:background 属性。

      (3) 在你的adapter的开头和结尾创建一个缓冲区,分别由last/first项组成,当用户在缓冲区中滚动足够远时,跳转到画廊另一端的匹配项无限的“轮播”画廊。

      【讨论】:

      • 这些都是不适合我的选项。目前我只是使用 Horizo​​ntalScrollView 并动态添加项目以使两侧没有空间。
      • 如果选定的图库项目不重要,您可以覆盖图库扩展中的 fling 和 touch 方法并防止滚动到最终项目。 (如果 selectedPosition items-2 && 试图向右滚动:返回;)
      • 我认为只要稍微调整一下,我就能找到一个可行的解决方案。它仍然不理想,但比其他任何东西都好。
      • 是的,根据您的需要,您最好只实现自己的水平列表。毕竟,这可能比修改图库更方便。
      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

        您可能在谈论褪色边缘长度。

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

        试试

        setFadingEdgeLength(0);
        

        或者

         setHorizontalFadingEdgeEnabled(false);
        

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

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

        【讨论】:

        • 抱歉延迟回复 chris,但不,这不是我想我说的空间,我有一个画廊,用项目填满屏幕的整个宽度......但是无论如何,我有一个空白空间,我可以在最后一个和第一个项目的左侧和右侧滚动槽,我想摆脱它,就像开始之前和结束之前的空间......我想要那个。谢谢。
        • 你能把所有的 xml 发布到你的视图中吗?也许父母的设置正在影响它?
        • 抱歉,耽搁了,这是画廊活动和我的自定义项目的图像和整个代码
        • 将 layout_width 更改为 fill_parent。还可以尝试将重力设置为左侧。这可能会将一切推向一边。
        • 不,没用 :( 你在图片中看到的是保龄球记分员的前 3 帧,当我将画廊滚动到最右侧时,我得到了完全相同的结果空间。我什至尝试为宽度添加一个固定值,但也没有这样做。
        【解决方案6】:

        我刚刚在这个问题上花了 2 个小时,终于找到了适合自己的解决方案。我有一个带有自定义 LinearLayout 元素的画廊。我想一次只显示 1 个元素,在开头和结尾都没有任何填充。

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

        彼得 B.

        【讨论】:

        • 不,它对我不起作用,我更新了我的原始帖子,并用图片说明了我的问题实际上是什么样的,无论如何感谢您的帮助,还有其他想法吗?
        猜你喜欢
        • 2016-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-07
        • 2011-09-30
        • 2018-11-07
        • 1970-01-01
        • 2016-02-03
        相关资源
        最近更新 更多