gpt4 book ai didi

android - 约束布局不对齐 TextView

转载 作者:行者123 更新时间:2023-11-29 23:45:41 25 4
gpt4 key购买 nike

我正在使用约束布局在屏幕的每个角落对齐我的 TextView ,但它看起来不起作用。屏幕右侧大小的文本根据左侧大小的文本长度对齐。看看附件图片。右侧的文本未正确对齐。由于某种原因,有一些空间关闭。如何解决?

enter image description here

<?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="wrap_content">


<TextView
android:id="@+id/payout_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:text="@string/payout_label"
app:layout_constraintBottom_toTopOf="@+id/income_icon"/>


<ImageView
android:id="@+id/income_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="30dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="-50dp"
android:padding="1dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_income"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_chainStyle="packed" />

<TextView
android:id="@+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:text="Salary"
app:layout_constraintTop_toTopOf="@+id/income_icon"
app:layout_constraintStart_toEndOf="@+id/income_icon"
/>

<TextView
android:id="@+id/income_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$0.00"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/green"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.91"
app:layout_constraintStart_toEndOf="@+id/category"
app:layout_constraintTop_toTopOf="@+id/income_icon" />

<TextView
android:id="@+id/frequency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="-5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/grey"
android:text="Monthly"
app:layout_constraintStart_toEndOf="@+id/income_icon"
app:layout_constraintBottom_toBottomOf="@+id/income_icon" />

<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pending"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@color/grey"
app:layout_constraintBottom_toBottomOf="@+id/income_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.91"
app:layout_constraintStart_toEndOf="@+id/frequency" />
</android.support.constraint.ConstraintLayout>

最佳答案

如果希望金额右对齐对齐,则不需要下面两行XML:

    app:layout_constraintHorizontal_bias="0.91"
app:layout_constraintStart_toEndOf="@+id/category"

因此,只需删除它们即可得到以下内容:

<TextView
android:id="@+id/income_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$0.00"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/green"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/income_icon" />

如果您需要在右侧留出边距,例如 16dp,请添加:

android:layout_marginEnd="16dp"

关于android - 约束布局不对齐 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51461896/

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