Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android constraintLayout-如何使用水平屏障向上移动?_Android_Android Constraintlayout - Fatal编程技术网

android constraintLayout-如何使用水平屏障向上移动?

android constraintLayout-如何使用水平屏障向上移动?,android,android-constraintlayout,Android,Android Constraintlayout,我需要一个介于视图和文本视图之间的视图。基本上,我想发生的是,如果文本水平增长,那么它应该向上推动屏障。以下是我到目前为止的情况: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="htt

我需要一个介于视图和文本视图之间的视图。基本上,我想发生的是,如果文本水平增长,那么它应该向上推动屏障。以下是我到目前为止的情况:

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

看看我的障碍代码,它应该向上,因为我的方向设置为“顶部”。但是当我添加一堆文本时,它不会向上推。为什么?基本上有一个叫做line3的视图,当textview水平增长时,我希望该视图向上推。所以我在line3和textview之间设置了屏障。我错过了什么?

您还记得添加:

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

它不会飞到顶端,因为你已经把它修好了,让它留在那里。这一行
app:layout\u constraintTop\u toBottomOf=“@id/line2”
将确保它保持在那里,您必须删除它。:)如果我移除它,它就不会有垂直约束。如果我删除了您需要使用relativeLayout的约束,如何使其不移动到顶部。添加约束会将其固定在特定位置。另一个建议是,如果你想显示所有的文本,你也可以在文本视图中添加滚动条?这些已经存在了。为什么我要使用“开始”我希望它向上移动