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

时间:2016-12-11 19:33:50

标签: android android-layout android-fragments android-constraintlayout

我正在尝试将SELECT e.Namee,w.DayName,s.StartTime,s.Hours FROM Schedule s INNER JOIN Employees e INNER JOIN WeekDay w ON s.Emp_ID = e.ID ON s.Weekday = w.ID; 水平放置在约束布局中,但问题是8 Image Views 2 Image Views水平占据整个屏幕,第三个图像位于屏幕外。

当我使用普通布局时,我将所有这些放在200X200中。

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

请指导我。

2 个答案:

答案 0 :(得分:1)

您的视图层次结构应该是这样的:

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

约束布局减少了嵌套。这并不意味着它也可以用来代替可滚动视图。您可以将可滚动视图的子项从相对/线性布局替换为约束布局,如上所述。

PS:你为什么放置八个&#39;水平滚动视图中的图像视图? 请尝试使用带有ImageView项目的RecyclerView

答案 1 :(得分:0)

以下是使用ConstraintLayout的Horizo​​ntalScrollView的示例。

<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>
相关问题