gpt4 book ai didi

android - ConstratintLayout : How to center a view according to another view, 垂直

转载 作者:搜寻专家 更新时间:2023-11-01 09:30:15 26 4
gpt4 key购买 nike

我有以下代码

<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:padding="16dp"
tools:context="gr.teiath.cs.android.tipcalculator.MainActivity">

<TextView
android:id="@+id/AmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amount"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@id/AmountTV"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/Amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:digits="0123456789"
android:inputType="numberDecimal"
android:maxLength="10"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/AmountLabel"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

这导致了

enter image description here

我不知道我描述的是否正确,但我想根据金额 EditText 垂直居中金额 TextView。现在,TextViewEditText 的顶部对齐。我想做成这样。

enter image description here

我为此添加了 layout_marginTop10dp,但我认为这不是实现它的方法。提前致谢。

最佳答案

试试这个

<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:padding="16dp">


<TextView
android:id="@+id/AmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amount"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBaseline_toBaselineOf="@id/Amount"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/Amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:digits="0123456789"
android:inputType="numberDecimal"
android:maxLength="10"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/AmountLabel"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

输出

enter image description here

关于android - ConstratintLayout : How to center a view according to another view, 垂直,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47696326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com