ConstraintLayout在重绘时损坏

时间:2017-06-29 11:54:38

标签: android android-constraintlayout

所以,我不知道为什么会这样做,但我会尝试解释。在我摆脱了50%的应用程序之前,它从未习惯过:layout_constraintDimensionRatio flag

这是我的观点,很好:

enter image description here

现在,如果我显示一个AlertDialog,或者推送到另一个屏幕然后回来,我会得到这个

enter image description here

我没有在代码中更改布局。触发的唯一事件是隐藏导航栏,如果我取出导航栏,则没有任何区别。

public void onWindowFocusChanged(boolean hasFocus){
        super.onWindowFocusChanged(hasFocus);
        hideNavigationBar();
    }

    public void hideNavigationBar()
    {
        View decorView = getWindow().getDecorView();
        // Hide both the navigation bar and the status bar.
        // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
        // a general rule, you should design your app to hide the status bar whenever you
        // hide the navigation bar.

        int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        decorView.setSystemUiVisibility(uiOptions);

    }

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:background="@android:color/holo_blue_bright">

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/holo_blue_bright"
        android:clickable="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/activity_form"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_blue_bright"
            android:clickable="true"
            android:focusableInTouchMode="true">

            <ImageView
                android:id="@+id/top_footer"
                android:layout_width="0dp"
                android:layout_height="296dp"
                app:srcCompat="@drawable/thumbs_gradient_top"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/close_button"
                android:layout_width="230dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="12dp"
                android:background="@null"
                android:drawableLeft="@drawable/icn_chevron_left"
                android:text="@string/back_to_o2_home_story"
                android:textAllCaps="false"
                android:textColor="#FFF"
                android:textSize="18sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                />


            <TextView
                android:id="@+id/title"
                android:layout_width="300dp"
                android:layout_height="170dp"
                android:layout_marginTop="10dp"
                android:fontFamily="monospace"
                android:text="Choose what matters most to you."
                android:textAlignment="textStart"
                android:textColor="@android:color/white"
                android:textSize="40sp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/close_button"
                app:layout_constraintLeft_toLeftOf="parent" />


            <ImageButton
                android:id="@+id/left1"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                android:layout_marginTop="20dp"
                app:layout_constraintRight_toLeftOf="@+id/right1"
                app:layout_constraintTop_toBottomOf="@+id/title"
                android:background="@drawable/dog_tick_off"
                app:layout_constraintLeft_toLeftOf="parent" />

            <ImageButton
                android:id="@+id/right1"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                android:layout_marginTop="20dp"
                app:layout_constraintBottom_toTopOf="@+id/right2"
                app:layout_constraintLeft_toRightOf="@+id/left1"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/title"
                android:background="@drawable/elderly_tick_off" />

            <ImageButton
                android:id="@+id/left2"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/left3"
                app:layout_constraintRight_toLeftOf="@+id/right2"
                app:layout_constraintTop_toBottomOf="@+id/left1"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/car_tick_off" />

            <ImageButton
                android:id="@+id/right2"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/right3"
                app:layout_constraintLeft_toRightOf="@+id/left2"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/left2"
                android:background="@drawable/baby_tick_off" />

            <ImageButton
                android:id="@+id/left3"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/left4"
                app:layout_constraintRight_toLeftOf="@+id/right3"
                app:layout_constraintTop_toBottomOf="@+id/left2"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/flowershop_tick_off" />

            <ImageButton
                android:id="@+id/right3"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/right4"
                app:layout_constraintLeft_toRightOf="@+id/left3"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/left3"
                android:background="@drawable/mug_tick_off" />

            <ImageButton
                android:id="@+id/left4"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/left5"
                app:layout_constraintRight_toLeftOf="@+id/right4"
                app:layout_constraintTop_toBottomOf="@+id/left3"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/piggy_tick_off" />

            <ImageButton
                android:id="@+id/right4"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/right5"
                app:layout_constraintLeft_toRightOf="@+id/left4"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/left4"
                android:background="@drawable/swimming_tick_off" />

            <ImageButton
                android:id="@+id/left5"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/left6"
                app:layout_constraintRight_toLeftOf="@+id/right5"
                app:layout_constraintTop_toBottomOf="@+id/left4"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/social_tick_off" />

            <ImageButton
                android:id="@+id/right5"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/right6"
                app:layout_constraintLeft_toRightOf="@+id/left5"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/left5"
                android:background="@drawable/teenager_tick_off" />

            <ImageButton
                android:id="@+id/left6"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/left7"
                app:layout_constraintRight_toLeftOf="@+id/right6"
                app:layout_constraintTop_toBottomOf="@+id/left5"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/yoga_tick_off" />

            <ImageButton
                android:id="@+id/right6"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintBottom_toTopOf="@+id/right7"
                app:layout_constraintLeft_toRightOf="@+id/left6"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/left6"
                android:background="@drawable/door_tick_off" />


            <ImageButton
                android:id="@+id/left7"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:layout_marginBottom="360dp"
                android:padding="0dp"
                app:layout_constraintBottom_toBottomOf="@+id/bottom_footer"
                app:layout_constraintRight_toLeftOf="@+id/right7"
                app:layout_constraintTop_toBottomOf="@+id/left6"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/tv_tick_off" />

            <ImageButton
                android:id="@+id/right7"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:layout_marginBottom="360dp"
                android:padding="0dp"
                app:layout_constraintBottom_toBottomOf="@+id/bottom_footer"
                app:layout_constraintLeft_toRightOf="@+id/left7"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/left7"
                android:background="@drawable/security_tick_off" />


            <ImageView
                android:id="@+id/bottom_footer"
                android:layout_width="0dp"
                android:layout_height="370dp"
                app:srcCompat="@drawable/thumbs_gradient_bottom"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

            <EditText
                android:id="@+id/nameEditText"
                android:layout_width="300dp"
                android:layout_height="50dp"
                android:layout_marginTop="60dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@android:color/background_light"
                android:hint="@string/name"
                android:inputType="textPersonName|textCapWords"
                android:padding="10dp"
                android:textColorHint="#0000ff"
                app:layout_constraintTop_toTopOf="@+id/bottom_footer"
                app:layout_constraintLeft_toRightOf="parent"
                app:layout_constraintRight_toLeftOf="parent" />

            <EditText
                android:id="@+id/mobileEditText"
                android:layout_width="300dp"
                android:layout_height="50dp"
                android:layout_marginTop="30dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@android:color/background_light"
                android:hint="@string/mobile_number"
                android:inputType="phone"
                android:padding="10dp"
                android:textColorHint="#0000ff"
                app:layout_constraintTop_toBottomOf= "@+id/nameEditText"
                app:layout_constraintLeft_toRightOf="parent"
                app:layout_constraintRight_toLeftOf="parent" />

            <TextView
                android:id="@+id/legal_text"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:fontFamily="monospace"
                android:text="Legal text will go here etc"
                android:textAlignment="textStart"
                android:textColor="@android:color/white"
                android:textSize="12sp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/mobileEditText"
                app:layout_constraintLeft_toLeftOf="parent" />

            <ImageButton
                android:id="@+id/submitButton"
                android:layout_width="314dp"
                android:layout_height="52dp"
                android:layout_gravity="bottom"
                android:layout_marginBottom="80dp"
                android:layout_marginEnd="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginStart="10dp"
                android:background="@drawable/btn_start_pink"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/legal_text"
                app:layout_constraintRight_toRightOf="parent" />


            <android.support.constraint.Guideline
                android:id="@+id/ceter_guideline"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.5"
                tools:layout_editor_absoluteY="0dp"
                tools:layout_editor_absoluteX="180dp" />

        </android.support.constraint.ConstraintLayout>

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

1 个答案:

答案 0 :(得分:0)

所以,我无法弄清楚为什么它只影响并行图像而没有别的。我基本上清除了所有约束并再次构建它

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:background="@android:color/holo_blue_bright">

    <ScrollView
        android:layout_width="360dp"
        android:layout_height="640dp"
        android:background="@android:color/holo_blue_bright"
        android:clickable="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/activity_form"
            android:layout_width="360dp"
            android:layout_height="640dp"
            android:background="@android:color/holo_blue_bright"
            android:clickable="true"
            android:focusableInTouchMode="true">

            <ImageView
                android:id="@+id/top_footer"
                android:layout_width="0dp"
                android:layout_height="296dp"
                app:srcCompat="@drawable/thumbs_gradient_top"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/close_button"
                android:layout_width="230dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="12dp"
                android:background="@null"
                android:drawableLeft="@drawable/icn_chevron_left"
                android:text="@string/back_to_o2_home_story"
                android:textAllCaps="false"
                android:textColor="#FFF"
                android:textSize="18sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                />


            <TextView
                android:id="@+id/title"
                android:layout_width="300dp"
                android:layout_height="170dp"
                android:layout_marginTop="10dp"
                android:fontFamily="monospace"
                android:text="Choose what matters most to you."
                android:textAlignment="textStart"
                android:textColor="@android:color/white"
                android:textSize="40sp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/close_button"
                app:layout_constraintLeft_toLeftOf="parent" />


            <ImageButton
                android:id="@+id/left1"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                android:layout_marginTop="20dp"
                app:layout_constraintTop_toBottomOf="@+id/title"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/dog_tick_off" />

            <ImageButton
                android:id="@+id/right1"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                android:layout_marginTop="20dp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/title"
                android:background="@drawable/elderly_tick_off" />

            <ImageButton
                android:id="@+id/left2"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintTop_toBottomOf="@+id/left1"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/car_tick_off" />

            <ImageButton
                android:id="@+id/right2"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintLeft_toRightOf="@+id/left2"
                app:layout_constraintTop_toBottomOf="@+id/right1"
                android:background="@drawable/baby_tick_off" />

            <ImageButton
                android:id="@+id/left3"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintTop_toBottomOf="@+id/left2"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/flowershop_tick_off" />

            <ImageButton
                android:id="@+id/right3"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/right2"
                android:background="@drawable/mug_tick_off" />

            <ImageButton
                android:id="@+id/left4"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintTop_toBottomOf="@+id/left3"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/piggy_tick_off" />

            <ImageButton
                android:id="@+id/right4"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/right3"
                android:background="@drawable/swimming_tick_off" />

            <ImageButton
                android:id="@+id/left5"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintTop_toBottomOf="@+id/left4"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/social_tick_off" />

            <ImageButton
                android:id="@+id/right5"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/right4"
                android:background="@drawable/teenager_tick_off" />

            <ImageButton
                android:id="@+id/left6"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintTop_toBottomOf="@+id/left5"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/yoga_tick_off" />

            <ImageButton
                android:id="@+id/right6"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/right5"
                android:background="@drawable/door_tick_off" />


            <ImageButton
                android:id="@+id/left7"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintTop_toBottomOf="@+id/left6"
                app:layout_constraintLeft_toLeftOf="parent"
                android:background="@drawable/tv_tick_off" />

            <ImageButton
                android:id="@+id/right7"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="180dp"
                android:layout_height="160dp"
                android:padding="0dp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/right6"
                android:background="@drawable/security_tick_off" />


            <ImageView
                android:id="@+id/bottom_footer"
                android:layout_width="0dp"
                android:layout_marginTop="150dp"
                android:layout_height="370dp"
                app:srcCompat="@drawable/thumbs_gradient_bottom"
                app:layout_constraintTop_toBottomOf="@+id/left6"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

            <EditText
                android:id="@+id/nameEditText"
                android:layout_width="300dp"
                android:layout_height="50dp"
                android:layout_marginTop="60dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@android:color/background_light"
                android:hint="@string/name"
                android:inputType="textPersonName|textCapWords"
                android:padding="10dp"
                android:textColorHint="#0000ff"
                app:layout_constraintTop_toTopOf="@+id/bottom_footer"
                app:layout_constraintLeft_toRightOf="parent"
                app:layout_constraintRight_toLeftOf="parent" />

            <EditText
                android:id="@+id/mobileEditText"
                android:layout_width="300dp"
                android:layout_height="50dp"
                android:layout_marginTop="30dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@android:color/background_light"
                android:hint="@string/mobile_number"
                android:inputType="phone"
                android:padding="10dp"
                android:textColorHint="#0000ff"
                app:layout_constraintTop_toBottomOf= "@+id/nameEditText"
                app:layout_constraintLeft_toRightOf="parent"
                app:layout_constraintRight_toLeftOf="parent" />

            <TextView
                android:id="@+id/legal_text"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:fontFamily="monospace"
                android:text="Legal text will go here etc"
                android:textAlignment="textStart"
                android:textColor="@android:color/white"
                android:textSize="12sp"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/mobileEditText"
                app:layout_constraintLeft_toLeftOf="parent" />

            <ImageButton
                android:id="@+id/submitButton"
                android:layout_width="314dp"
                android:layout_height="52dp"
                android:layout_gravity="bottom"
                android:layout_marginBottom="80dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/btn_start_pink"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/legal_text"
                app:layout_constraintRight_toRightOf="parent" />

        </android.support.constraint.ConstraintLayout>

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