在约束布局中,障碍没有设置为referenceIds吗? [英] Barrier doesn't set to referenceIds in constraint layout?

查看:61
本文介绍了在约束布局中,障碍没有设置为referenceIds吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天,我正在探索约束布局.我可以理解障碍的概念,但是当我实现时,我无法获得正确的输出.

hey last few days I am exploring about the constraint layout.the concept of barrier I can understand but when i implement I can't get the correct output.

我想在正确的方向上设置障碍以引用ID.但是障碍不起作用,它应该为nameLabel和passionLabel视图设置.请帮我.先感谢您.这是当前输出

I want to set the barrier in the right direction to reference Id's. But barrier doesn't work.it should set for the views which are nameLabel and passionLabel. please help me. thank you in advance. This is the current output

<?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:id="@+id/activity_main_barriers"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:fontFamily="@font/roboto_bold"
        android:text="@string/barriers"
        android:textColor="@color/black"
        android:textSize="25sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/header"
        android:layout_width="0dp"
        android:layout_height="149dp"
        android:layout_marginTop="8dp"
        android:scaleType="centerCrop"
        android:src="@drawable/arun"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:fontFamily="@font/roboto_bold"
        android:text="Arun Pandian"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.032"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/header" />
    <!--@string/hobbies-->
    <TextView
        android:id="@+id/passionLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:labelFor="@+id/etPassion"
        android:text="@string/passion"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="15sp"
        app:layout_constraintBaseline_toBaselineOf="@+id/etPassion"
        app:layout_constraintStart_toStartOf="@+id/nameLabel" />
    <TextView
        android:id="@+id/nameLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:fontFamily="@font/roboto_italic"
        android:labelFor="@+id/cameraType"
        android:text="@string/name"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="15sp"
        app:layout_constraintBaseline_creator="1"
        app:layout_constraintBaseline_toBaselineOf="@+id/etName"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintStart_toStartOf="@+id/title"
        app:layout_editor_absoluteX="16dp"
        app:layout_editor_absoluteY="189dp"
        tools:layout_constraintBaseline_creator="0"
        tools:layout_constraintLeft_creator="0" />
    <EditText
        android:id="@+id/etPassion"
        android:layout_width="217dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Developing softwares"
        app:layout_constraintEnd_toEndOf="@+id/etName"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/etName"
        app:layout_constraintTop_toBottomOf="@+id/etName"
        app:layout_editor_absoluteX="73dp"
        app:layout_editor_absoluteY="225dp"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="0" />
    <EditText
        android:id="@+id/etName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="148dp"
        android:inputType="textPersonName"
        android:text="Arun Pandian"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/tvName"
        app:layout_constraintTop_toBottomOf="@+id/title"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="0" />
    <android.support.constraint.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="end"
        app:constraint_referenced_ids="nameLabel,passionLabel"
        tools:layout_editor_absoluteX="411dp" />
</android.support.constraint.ConstraintLayout>

推荐答案

尝试一下: 您必须将两个edittext开始约束都设置为barrier.

Try this: you have to give both edittext start constraint to barrier.

此外,当我在android studio xml中看到我的输出时,与您在问题图像中发布的内容相同.检查 http://prntscr.com/mkdtgb

Also when I see in My android studio xml my output is same as you post in your question image. check http://prntscr.com/mkdtgb

但是当我在设备中看到它正在运行时

But when I see in device it's working

 <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:id="@+id/activity_main_barriers"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:text="barriers"
        android:textColor="@android:color/black"
        android:textSize="25sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/header"
        android:layout_width="0dp"
        android:layout_height="149dp"
        android:layout_marginTop="8dp"
        android:scaleType="centerCrop"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <TextView
        android:id="@+id/title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:text="Arun Pandian"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/header" />
    <!--@string/hobbies-->
    <TextView
        android:id="@+id/passionLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:labelFor="@+id/etPassion"
        android:text="passios"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="15sp"
        app:layout_constraintBaseline_toBaselineOf="@+id/etPassion"
        app:layout_constraintStart_toStartOf="@+id/nameLabel" />

    <EditText
        android:id="@+id/etPassion"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:layout_marginStart="16dp"
        android:text="Developing softwares"
        app:layout_constraintEnd_toEndOf="@+id/etName"
        app:layout_constraintStart_toEndOf="@+id/barrier2"
        app:layout_constraintTop_toBottomOf="@+id/etName" />

    <TextView
        android:id="@+id/nameLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:labelFor="@+id/cameraType"
        android:text="namegfhfgdfgdfgdfgdfgdfgdf"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="15sp"
        app:layout_constraintBaseline_toBaselineOf="@+id/etName"
        app:layout_constraintStart_toStartOf="parent" />

    <EditText
        android:id="@+id/etName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:inputType="textPersonName"
        android:text="Arun Pandian"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/barrier2"
        app:layout_constraintTop_toBottomOf="@+id/title" />


    <android.support.constraint.Barrier
        android:id="@+id/barrier2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="end"
        app:constraint_referenced_ids="nameLabel,passionLabel" />
    
</android.support.constraint.ConstraintLayout>

这篇关于在约束布局中,障碍没有设置为referenceIds吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆