当使用约束放置视图时,Horizo​​ntalScrollView不使用ConstraintLayout

时间:2018-04-20 05:59:38

标签: android android-constraintlayout horizontalscrollview

我想将Contraintlayout包装在Horizo​​ntalScrollView中,如this, 这是代码:

    <HorizontalScrollView
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/black">

        <ImageView
            android:id="@+id/imageView_dis1"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/imageView_dis2"
            app:layout_constraintTop_toTopOf="parent"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1"/>


            <ImageView
                android:id="@+id/imageView_dis1_pow1"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>



            <ImageView
                android:id="@+id/imageView_dis1_pow2"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow1"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow3"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow2"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow4"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow3"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow5"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow4"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow6"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow5"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow7"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow6"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow8"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow7"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow9"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow8"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>

            <ImageView
                android:id="@+id/imageView_dis1_pow10"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView_dis1"
                app:layout_constraintTop_toTopOf="@id/imageView_dis1"
                app:layout_constraintStart_toEndOf="@id/imageView_dis1_pow9"
                android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
                app:layout_constraintDimensionRatio="H,1:1"/>





        <ImageView
            android:id="@+id/imageView_dis2"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/imageView_dis3"
            app:layout_constraintTop_toBottomOf="@+id/imageView_dis1"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1"  />

        <ImageView
            android:id="@+id/imageView_dis3"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/imageView_dis4"
            app:layout_constraintTop_toBottomOf="@+id/imageView_dis2"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1" />

        <ImageView
            android:id="@+id/imageView_dis4"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/imageView_dis5"
            app:layout_constraintTop_toBottomOf="@+id/imageView_dis3"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1" />

        <ImageView
            android:id="@+id/imageView_dis5"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/imageView_dis6"
            app:layout_constraintTop_toBottomOf="@+id/imageView_dis4"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1" />

        <ImageView
            android:id="@+id/imageView_dis6"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/imageView_dis7"
            app:layout_constraintTop_toBottomOf="@+id/imageView_dis5"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1" />

        <ImageView
            android:id="@+id/imageView_dis7"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/imageView_dis8"
            app:layout_constraintTop_toBottomOf="@+id/imageView_dis6"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1" />

        <ImageView
            android:id="@+id/imageView_dis8"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageView_dis7"
            android:src="@drawable/common_google_signin_btn_icon_dark_normal_background"
            app:layout_constraintDimensionRatio="H,1:1" />


    </android.support.constraint.ConstraintLayout>
</HorizontalScrollView>

但是我无法横向滚动,当使用app:layout:contraintStart_toEndOf="ImageView"水平放置图片时,问题显而易见,如果我只是放置一个LinearLayout它按预期工作。 知道为什么会这样吗?我使用约束布局1.1.0

1 个答案:

答案 0 :(得分:0)

我测试了上面的示例并得出结论,如果您在从父级到父级底部的子视图中有完全垂直约束,则水平滚动不起作用。

如果您从import numpy as np # array operations import pandas as pd # time series management from pandas_datareader import data as web # data retrieval import matplotlib.pyplot as plt # standard plotting library import seaborn as sns; sns.set() # nicer plotting style import datetime start = datetime.datetime(2010, 1, 1) end = datetime.datetime(2018, 4, 19) f = web.DataReader('F', 'morningstar', start, end) print(f.tail) f['SMA50'] = pd.rolling_mean(f['Close'], window=50) #OLD f['SMA50'] = pd.Series(f).rolling(window=50).mean() #NEW 移除app:layout_constraintBottom_toBottomOf或将固定宽度(或设置为@+id/imageView_dis8的高度)设置为layout_constraintDimensionRatio水平滚动再次有效 - 尽管您已完成然后扭曲布局。

这一观察显然也是here