【发布时间】:2023-04-10 20:16:01
【问题描述】:
出于某种奇怪的原因,我的ConstraintLayout 中的TextViews 不会让步以显示所有文本,而且它似乎超出了屏幕的边界。我已经尝试过将app:layout_constrainedWidth="true" 与android:layout_width="wrap_content" 一起使用,但这对改变定位没有任何影响,这让我想到当我在其中添加更长的文本时,“1C”和“1D”文本视图会发生什么。
当前结果
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
app:cardUseCompatPadding="true"
android:background="@android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayoutA"
android:padding="12dp"
android:foreground="?android:attr/selectableItemBackground">
<!--Constraint 1-->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/constraintLayoutTitle"
android:layout_marginBottom="10dp">
<ImageView
android:id="@+id/ibA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/tvA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constraintStart_toEndOf="@+id/ibA"
app:layout_constraintTop_toTopOf="parent"
app:layout_constrainedWidth="true"
style="@android:style/TextAppearance.Medium"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!--Constraint 2-->
<androidx.constraintlayout.widget.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:id="@+id/constraintLayout">
<ImageView
android:id="@+id/ivA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/tvB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constraintStart_toEndOf="@+id/ivA"
app:layout_constraintTop_toTopOf="@+id/ivA"
style="@android:style/TextAppearance.Medium"/>
<TextView
android:id="@+id/tvC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
app:layout_constraintBottom_toTopOf="@+id/tvD"
app:layout_constraintStart_toEndOf="@+id/ivA"
app:layout_constraintTop_toBottomOf="@+id/tvB"
style="@android:style/TextAppearance.Medium"/>
<ImageView
android:id="@+id/ivD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="@+id/ivA"
app:layout_constraintStart_toStartOf="@+id/ivA"
app:layout_constraintTop_toBottomOf="@+id/ivA"
app:layout_constraintTop_toTopOf="@+id/tvD"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/tvD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constraintStart_toEndOf="@+id/ivD"
app:layout_constraintTop_toBottomOf="@+id/tvC"
style="@android:style/TextAppearance.Medium"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Suraj Vaishnav 的建议
【问题讨论】:
标签: android xml android-layout android-constraintlayout android-cardview