【问题标题】:How to use Horizontal ScrollView With one Fixed layout positioned at center?如何使用位于中心的一个固定布局的水平滚动视图?
【发布时间】:2018-03-27 18:07:07
【问题描述】:

我想用位于中心的固定布局来实现水平布局。但问题是,当我将布局保持在中心时,水平滚动视图子布局将与我保持在中心的固定布局重叠。如何分隔水平滚动视图上的空间,以便在滚动滚动视图时,子视图将跳转我们定义的空间并定位在中心布局的右侧和左侧。 怎么可能?请给出一些想法。如果你提供我的代码很高兴。希望有积极的回应。

【问题讨论】:

  • 您可以使用相对布局,将 imageview 保持在 parent 的左侧 - 水平滚动视图的其余部分在 imageview 的右侧
  • 你能详细说明一下吗?

标签: android android-layout horizontal-scrolling horizontalscrollview


【解决方案1】:

尝试使用FrameLayout:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:background="@color/main_background"
    android:layout_height="wrap_content">


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

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        app:srcCompat="@android:drawable/ic_delete" />
</FrameLayout>

希望这会有所帮助。

【讨论】:

  • 它会隐藏在中心位置的水平滚动视图的图标吗?
  • 您需要创建自定义水平滚动视图
  • 不知道自定义水平滚动视图。你能帮帮我吗?
【解决方案2】:

您可以利用 FRAME 布局,将 imageview 的重力保持在中心 - 水平滚动视图的其余部分保持原样。

参考下面的代码

    <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@android:drawable/ic_delete" />
</FrameLayout>

【讨论】:

  • 我想将图像视图保持在中心。保持在中心时出现问题。 Image View 将隐藏我保留在水平 ScrollView 上的图标。
  • 在这种情况下,您也可以使用框架布局,但您需要在水平滚动视图中保留一些空间。检查更新的答案
  • 水平滚动视图中显示的图标是动态的,可能有 3 4 5 6 7 8 等等...这种情况下如何保持空间?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-09
  • 2012-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多