ConstraintLayout尽管受限于查看

时间:2018-03-04 18:31:29

标签: android android-constraintlayout

搜索一下,无法专门找到这个问题。专门创建了一个帐户来询问这里发生了什么?!

第一次使用ConstraintLayout - 我取得了很好的成功,但由于某种原因,我不能让我的两个组件发挥得很好。

这就是我希望它看起来像(通过破坏约束和硬编码来完成):

enter image description here

......如果我试图约束" LabelJournal"这就是我弄得一团糟的混乱。和" linearLayout2":

enter image description here

名为" LabelJournal"的组件正在出现问题。和" linearLayout2"。这就是我的LayoutFile的样子......它是一个WIP,所以我现在知道那里有很多文本值的硬编码等等 - 我只想弄清楚什么在世界正在导致这两个组件卡在父母的顶端:

<?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">

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@android:color/transparent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_left" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_marginEnd="14dp"
        android:layout_marginStart="14dp"
        android:inputType="date"
        android:text="03/04/2018"
        android:textAlignment="center"
        android:textSize="24sp"
        app:layout_constraintEnd_toStartOf="@+id/imageButton2"
        app:layout_constraintStart_toEndOf="@+id/imageButton"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@android:color/transparent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_right" />

    <TextView
        android:id="@+id/LabelJournal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:text="Journal:"
        android:textStyle="italic"
        app:layout_constraintBottom_toTopOf="@id/ContentJournal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageButton" />

    <TextView
        android:id="@+id/ContentJournal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:text="The journal text would go in right about here. It should wrap to the next line for sufficientyl large text blocks."
        android:textColorLink="@android:color/black"
        android:textSize="18sp"
        app:layout_constraintBottom_toTopOf="@+id/LabelTags"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/LabelJournal" />

    <TextView
        android:id="@+id/LabelTags"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="16dp"
        android:text="Tags:"
        android:textStyle="italic"
        app:layout_constraintBottom_toTopOf="@+id/horizontalScrollView"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/ContentJournal" />

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView"
        android:layout_width="0dp"
        android:layout_height="41dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/LabelTags">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/TagDayOff"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical|center_horizontal"
                android:padding="10dp"
                android:paddingBottom="15dp"
                android:paddingTop="15dp"
                android:text="#DayOff"
                android:textAlignment="center"
                android:textColor="@android:color/darker_gray"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/TagUntracked"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical|center_horizontal"
                android:padding="10dp"
                android:paddingBottom="15dp"
                android:paddingTop="15dp"
                android:text="#Untracked"
                android:textAlignment="center"
                android:textColor="@android:color/darker_gray"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/TagTravel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical|center_horizontal"
                android:padding="10dp"
                android:paddingBottom="15dp"
                android:paddingTop="15dp"
                android:text="#Travel"
                android:textAlignment="center"
                android:textColor="@android:color/darker_gray"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/TagGames"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical|center_horizontal"
                android:padding="10dp"
                android:paddingBottom="15dp"
                android:paddingTop="15dp"
                android:text="#Games"
                android:textAlignment="center"
                android:textColor="@android:color/darker_gray"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/TagMovie"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center_vertical|center_horizontal"
                android:padding="10dp"
                android:paddingBottom="15dp"
                android:paddingTop="15dp"
                android:text="#Games"
                android:textAlignment="center"
                android:textColor="@android:color/darker_gray"
                android:textSize="18sp" />

        </LinearLayout>
    </HorizontalScrollView>

    <TextView
        android:id="@+id/LabelDIet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:text="Diet:"
        android:textStyle="italic"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/horizontalScrollView" />

    <TextView
        android:id="@+id/ContentCalories"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="8dp"
        android:textSize="18sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/LabelDIet"
        tools:text="2813" />

    <TextView
        android:id="@+id/DietCalLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:text="Cal"
        android:textSize="10sp"
        android:textStyle="italic"
        app:layout_constraintBottom_toBottomOf="@+id/ContentCalories"
        app:layout_constraintStart_toEndOf="@+id/ContentCalories" />

    <ProgressBar
        android:id="@+id/ProgressCalories"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="2dp"
        android:layout_marginEnd="-8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="2dp"
        android:progressDrawable="@android:color/holo_blue_dark"
        android:progressTint="@android:color/holo_green_light"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="@+id/ContentCalories"
        app:layout_constraintEnd_toEndOf="@+id/ContentProteinPercent"
        app:layout_constraintStart_toEndOf="@+id/DietCalLabel"
        app:layout_constraintTop_toTopOf="@+id/ContentCalories" />

    <TextView
        android:id="@+id/ContentProtein"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        android:textSize="18sp"
        app:layout_constraintEnd_toStartOf="@+id/DietCalLabel"
        app:layout_constraintTop_toBottomOf="@+id/ContentCalories"
        tools:text="154" />

    <TextView
        android:id="@+id/DietProteinLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:text="P"
        android:textSize="10sp"
        android:textStyle="italic"
        app:layout_constraintBottom_toBottomOf="@+id/ContentProtein"
        app:layout_constraintStart_toEndOf="@+id/ContentProtein" />

    <ProgressBar
        android:id="@+id/ProgressProtein"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="150dp"
        android:layout_height="0dp"
        android:layout_marginBottom="4dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="4dp"
        android:progressDrawable="@android:color/holo_blue_dark"
        android:progressTint="@android:color/holo_red_light"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="@+id/ContentProtein"
        app:layout_constraintStart_toEndOf="@+id/DietCalLabel"
        app:layout_constraintTop_toTopOf="@+id/ContentProtein" />

    <TextView
        android:id="@+id/ContentProteinPercent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:paddingEnd="8dp"
        android:paddingStart="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.074"
        app:layout_constraintStart_toEndOf="@+id/ProgressProtein"
        app:layout_constraintTop_toTopOf="@+id/ContentProtein"
        tools:text="22 %" />

    <TextView
        android:id="@+id/ContentFat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        android:textSize="18sp"
        app:layout_constraintEnd_toStartOf="@+id/DietCalLabel"
        app:layout_constraintTop_toBottomOf="@+id/ContentProtein"
        tools:text="103" />

    <TextView
        android:id="@+id/dietProteinLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:text="F"
        android:textSize="10sp"
        android:textStyle="italic"
        app:layout_constraintBottom_toBottomOf="@+id/ContentFat"
        app:layout_constraintStart_toEndOf="@+id/ContentFat" />

    <ProgressBar
        android:id="@+id/ProgressFats"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="150dp"
        android:layout_height="0dp"
        android:layout_marginBottom="4dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="4dp"
        android:progressDrawable="@android:color/holo_blue_dark"
        android:progressTint="@android:color/holo_orange_light"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="@+id/ContentFat"
        app:layout_constraintStart_toEndOf="@+id/DietCalLabel"
        app:layout_constraintTop_toTopOf="@+id/ContentFat" />

    <TextView
        android:id="@+id/contentProteinPercent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:paddingEnd="8dp"
        android:paddingStart="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.074"
        app:layout_constraintStart_toEndOf="@+id/ProgressProtein"
        app:layout_constraintTop_toTopOf="@+id/ContentFat"
        tools:text="33 %" />

    <TextView
        android:id="@+id/ContentCarbs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        android:textSize="18sp"
        app:layout_constraintEnd_toStartOf="@+id/DietCalLabel"
        app:layout_constraintTop_toBottomOf="@+id/ContentFat"
        tools:text="302" />

    <TextView
        android:id="@+id/DietCarbLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:text="C"
        android:textSize="10sp"
        android:textStyle="italic"
        app:layout_constraintBottom_toBottomOf="@+id/ContentCarbs"
        app:layout_constraintStart_toEndOf="@+id/ContentCarbs" />

    <ProgressBar
        android:id="@+id/ProgressCarbs"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="150dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="8dp"
        android:progressDrawable="@android:color/holo_blue_dark"
        android:progressTint="@android:color/holo_blue_light"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="@+id/ContentCarbs"
        app:layout_constraintStart_toEndOf="@+id/DietCalLabel"
        app:layout_constraintTop_toTopOf="@+id/ContentCarbs" />

    <TextView
        android:id="@+id/ContentCarbPercent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:paddingEnd="8dp"
        android:paddingStart="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.074"
        app:layout_constraintStart_toEndOf="@+id/ProgressProtein"
        app:layout_constraintTop_toTopOf="@+id/ContentCarbs"
        tools:text="43 %" />

    <TextView
        android:id="@+id/LabelExercise"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:text="Exercise:"
        android:textStyle="italic"
        app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ContentCarbs" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="436dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/LabelExercise" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageButton
                android:id="@+id/ImageExerciseAttribution"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:layout_weight="1"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/LabelExercise"
                app:srcCompat="@drawable/fit" />

            <TextView
                android:id="@+id/ContentExercise"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_weight="1"
                android:text="45 min - PHUL Upper Power"
                android:textSize="18sp"
                app:layout_constraintBottom_toBottomOf="@+id/ImageExerciseAttribution"
                app:layout_constraintStart_toEndOf="@+id/ImageExerciseAttribution"
                app:layout_constraintTop_toTopOf="@+id/ImageExerciseAttribution" />
        </LinearLayout>

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

也许我也应该提一下 - 我的约束布局中没有出现任何错误(尽管有大量关于硬编码文本的警告以及我以后会处理的内容)。

1 个答案:

答案 0 :(得分:0)

好吧花了我一个小时的修修补补 - 但是我的布局HTML中包含&#34; layout_constraintBottom_toTopOf&#34;引起了这个问题。我不知道它是订购的东西还是一些奇怪的绘图层次结构。这对我来说没有任何意义。