java - 如何修改约束布局中的链长?

标签 java android android-constraintlayout constraint-layout-chains

这是我的代码

<?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="@color/nav_and_action_bar_color"
 >

<ImageView
    android:id="@+id/some_person"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/some_person"
    app:layout_constraintBottom_toTopOf="@+id/et_username"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<EditText
    android:id="@+id/et_username"
    android:layout_width="@dimen/login_page_text_fields_width"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@android:color/white"
    android:hint="@string/email_hint"
    android:padding="10dp"
    app:layout_constraintBottom_toTopOf="@+id/et_password"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/some_person" />

<EditText
    android:id="@+id/et_password"
    android:layout_width="@dimen/login_page_text_fields_width"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@android:color/white"
    android:hint="@string/password_hint"
    android:inputType="textPassword"
    android:padding="10dp"
    app:layout_constraintBottom_toTopOf="@+id/login_button"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/et_username" />

<Button
    android:id="@+id/login_button"
    android:layout_width="@dimen/login_button_width"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@color/colorAccent"
    android:elevation="5dp"
    android:onClick="clickedOnLogin"
    android:text="@string/login_button"
    android:textColor="@android:color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/et_password" />
</android.support.constraint.ConstraintLayout>

结果我似乎得到了这个

emulator screenshot

如何将这些元素组合在一起?我希望他们靠得很近。

最佳答案

您需要为每个要应用链接逻辑的 View 定义变量。只选一个:

app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintVertical_chainStyle="spread_inside"

关于java - 如何修改约束布局中的链长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50481557/

相关文章:

java - 在抽屉导航中加载具有不同参数的单个 fragment

android - 在 ConstraintLayout 中将一个 View 放在另一个 View 的右侧

android - 如何通过可变尺寸的 TextView 防止 ImageView 在屏幕外为 "pushed"?

android - SMS_DELIVERED Intent 的 SMS 发送报告不起作用

android - 比例过渡动画

java - 重命名 hibernate envers id 和 timestamp 列

java - 如何确保抛出 HttpClientErrorException 会导致 HTTP 400 响应?

java - 当 List 包含非字母数字字符时,什么决定 Collections.sort 中的排序顺序?

java - "for x in list"在Java中怎么写?

java - 从 BackStack (Flag_Activity_no_history) 中删除 Activity 不起作用