androidconstraintLayout-如何使用水平障碍向上移动?

时间:2018-10-29 04:44:15

标签: android android-constraintlayout

我在视图和文本视图之间需要horizontal barrier。本质上,我想发生的是,如果文本水平增长,那么它应该将障碍向上推。这是我到目前为止所拥有的:

    <?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.support.constraint.Guideline
            android:id="@+id/guideline_start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="12dp" />

        <android.support.constraint.Guideline
            android:id="@+id/guideline_voucher_code_start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="24dp" />


        <android.support.constraint.Guideline
            android:id="@+id/guideline_end"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_end="5dp" />

        <ImageView
            android:id="@+id/iv"
            android:layout_width="match_parent"
            android:layout_height="405dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:background="@tools:sample/backgrounds/scenic" />


        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:background="@null"
            app:layout_constraintLeft_toLeftOf="@id/guideline_start"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/close_white_x" />


        <TextView
            android:id="@+id/tv_subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="19dp"
            android:fontFamily="@font/fui_medium_extd"
            android:gravity="center_horizontal"
            android:letterSpacing="0.07"
            android:lineSpacingExtra="6sp"
            android:textColor="#ffffff"
            android:textSize="11sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="NICE TO MEET YOU!" />

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="37dp"
            android:fontFamily="@font/bold"
            android:gravity="center_horizontal"
            android:letterSpacing="-0.02"
            android:shadowColor="#16000000"
            android:shadowDy="2"
            android:shadowRadius="9"
            android:textAlignment="center"
            android:textAllCaps="true"
            android:textColor="#ffffff"
            android:textSize="27sp"
            app:layout_constraintBottom_toBottomOf="@id/iv"
            app:layout_constraintEnd_toEndOf="@id/guideline_end"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="@id/guideline_start"
            tools:text="Enjoy 20% off your first purchase on the App." />

        <TextView
            android:id="@+id/tv_code"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="26dp"
            android:fontFamily="@font/fui_medium_extd"
            android:gravity="center_horizontal"
            android:letterSpacing="0.04"
            android:textColor="@color/black"
            android:textSize="20sp"
            app:layout_constraintBaseline_toBaselineOf="@id/btn_apply"
            app:layout_constraintLeft_toRightOf="@id/guideline_voucher_code_start"
            app:layout_constraintTop_toBottomOf="@id/iv"
            tools:text="APPY20" />

        <View
            android:id="@+id/line"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:background="@color/black"
            app:layout_constraintLeft_toLeftOf="@id/guideline_voucher_code_start"
            app:layout_constraintRight_toLeftOf="@id/btn_apply"
            app:layout_constraintTop_toBottomOf="@id/btn_apply" />

        <Button
            android:id="@+id/btn_apply"
            android:layout_width="81dp"
            android:layout_height="35dp"
            android:layout_marginTop="26dp"
            android:layout_marginRight="25dp"
            android:background="@color/action_blue"
            android:fontFamily="@font/fui_medium_extd"
            android:text="@string/APPLY"
            android:textColor="@color/white"
            android:textSize="10dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/iv" />

        <TextView
            android:id="@+id/tv_category_cta"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="29dp"
            android:fontFamily="@font/regular_extd"
            android:gravity="center_horizontal"
            android:text="SHOP NOW >"
            android:textAllCaps="true"
            android:textColor="@color/black"
            android:textSize="13sp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/line" />

        <View
            android:id="@+id/line2"
            android:layout_width="0dp"
            android:layout_height="1.5dp"
            android:background="@color/black"
            app:layout_constraintLeft_toLeftOf="@id/tv_category_cta"
            app:layout_constraintRight_toRightOf="@id/tv_category_cta"
            app:layout_constraintTop_toBottomOf="@id/tv_category_cta" />

        <View
            android:id="@+id/line3"
            android:layout_width="0dp"
            android:layout_height="3dp"
            android:layout_marginTop="29dp"
            android:background="#979797"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/line2"
            android:visibility="invisible"/>

        <android.support.constraint.Barrier
            android:id="@+id/barrier"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            app:barrierDirection="top"

            app:constraint_referenced_ids="line3"
             />
        <TextView
            android:id="@+id/tv_terms"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="9dp"
            android:layout_marginRight="11dp"
            android:gravity="center_horizontal"
            android:lineSpacingExtra="2sp"
            android:text="T&amp;C
Voucher code blah blah this text should push upwards, but its not, why ?
\n\n\n\n\n
adf
adf
dsa
fdafs\n
das\n
fda\n
sfadfs
adsf
asdf
asdf
asdf
asfd
asdf
asdf
asdf
asdf
\n\n\n\n
"
            android:textColor="#696969"
            android:textSize="8sp"
            app:layout_constraintLeft_toLeftOf="@id/guideline_start"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/line3" />


    </android.support.constraint.ConstraintLayout>

看看我拥有的障碍代码,因为我将方向设置为“ top”,所以它应该向上移动。但是当我添加一堆文本时,它不会向上推。为什么呢?本质上有一个称为line3的视图,我希望该视图在textview水平增长时向上推。所以我在第3行和textview之间放置了障碍。我错过了什么?

1 个答案:

答案 0 :(得分:-1)

您还记得添加:

app:barrierDirection="start"
app:constraint_referenced_ids="viewId,textId"