Android 如何在约束布局中创建水平滚动视图

Android 如何在约束布局中创建水平滚动视图,android,android-layout,android-fragments,android-constraintlayout,Android,Android Layout,Android Fragments,Android Constraintlayout,我试图在约束布局中水平放置8个图像视图,但问题是200X200的2个图像视图水平占据整个屏幕,第三个图像在屏幕外 当我使用普通布局时,我将所有这些都放在水平滚动视图中 我的问题是,我是否也需要在约束布局中使用水平滚动视图?如果是这样,那么我再次在这里创建嵌套布局 请指导我。您的视图层次结构应该如下所示: <HorizontalScrollView> <ConstraintLayout> <The 8 image views> <

我试图在约束布局中水平放置
8个图像视图
,但问题是
200X200
2个图像视图
水平占据整个屏幕,第三个图像在屏幕外

当我使用普通布局时,我将所有这些都放在
水平滚动视图中

我的问题是,我是否也需要在约束布局中使用水平滚动视图?如果是这样,那么我再次在这里创建嵌套布局


请指导我。

您的视图层次结构应该如下所示:

<HorizontalScrollView>
   <ConstraintLayout>  
      <The 8 image views>
   </ConstraintLayout>
</HorizontalScrollView>

约束布局可减少嵌套。这并不意味着它也可以用来代替可滚动视图。您可以将可滚动视图的子视图从相对/线性布局替换为约束布局,就像我上面所做的那样

PS:为什么要在水平滚动视图中放置“八”个图像视图?
尝试改用with ImageView项目。

下面是带有CONSTRAINTLAOUT的水平滚动视图示例

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    too`enter code here`ls:context="com.zoftino.androidui.ActivityScroll">
    <android.support.constraint.ConstraintLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button One"
            app:layout_constraintLeft_toRightOf="parent"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"></Button>
        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Two"
            app:layout_constraintLeft_toRightOf="@+id/button"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"></Button>
        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Three"
            app:layout_constraintLeft_toRightOf="@+id/button3"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"></Button>
        <Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Four"
            app:layout_constraintLeft_toRightOf="@+id/button4"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"></Button>
        <Button android:id="@+id/button7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Five"
            app:layout_constraintLeft_toRightOf="@+id/button6"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"></Button>
    </android.support.constraint.ConstraintLayout>
</HorizontalScrollView>