2

我需要一个水平滚动的视图列表,所以我将 LinearLayout 放在 Horizo​​ntalScrollView 中,并将元素添加到 LinearLayout。一切都很好,但是有奇怪的边距/填充(我不知道它是什么)

这是完全向左滚动的视图 - 第一项在父项上的一半

在此处输入图像描述

这是完全滚动到右侧的 - 右侧奇怪的填充

http://korniltsev.ru/m/gyazo/4d093939766fe.png

这是我的xml:

<HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <LinearLayout
                android:id="@+id/container"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"

                android:layout_gravity="center"/>
</HorizontalScrollView>

物品:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="150dp"
                android:layout_height="match_parent"
        >

    <FrameLayout
            android:layout_width="140dp"
            android:layout_height="50dp"
            android:background="@drawable/bg_payment_system_item"
            android:layout_centerInParent="true"
            >
        <ImageView
                android:id="@+id/icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                />
    </FrameLayout>
    <Button
        android:layout_width="30dp"
        android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"/>
</RelativeLayout>
4

2 回答 2

4

好的,所以这种行为是一个 android 错误。http://code.google.com/p/android/issues/detail?id=20088

于 2012-12-13T11:03:37.973 回答
0

您可以尝试代码中的策略,判断 HScroller 的内容宽度并与设备/容器宽度进行比较:

  1. 如果内容比容器宽:将内容的重力设置为“左”值

  2. 如果内容比容器薄:将内容的重力设置为“中心”值

我认为这只是需求的 UX 设计问题,该策略对我来说很好。

于 2017-03-06T03:37:46.567 回答