Kri*_*s B 2 android textview android-layout android-constraintlayout
我有一个ConstraintLayout包含 aTextView在文本末尾有一个小图像的文件。我遇到的这个问题是长文本没有换行。如果我修复了约束,TextView以便长文本将图像末尾包裹到屏幕的末尾:
截屏:
如果我添加app:layout_constraintEnd_toEndOf="parent"到TextView长文本换行但最后的图像不换行:
代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:padding="10dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/subscription_row_item_thumb"
android:layout_width="65dp"
android:layout_height="65dp"
android:scaleType="centerInside"
android:background="@drawable/all_circle_white_bg"
android:padding="1dp"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/subscription_row_item_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="@id/subscription_row_item_thumb"
app:layout_constraintStart_toStartOf="@id/subscription_row_item_thumb"
app:layout_constraintEnd_toEndOf="@id/subscription_row_item_thumb"/>
<TextView
android:id="@+id/subscription_row_item_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:breakStrategy="simple"
android:layout_marginStart="15dp"
android:textSize="16sp"
app:layout_constrainedWidth="true"
app:drawableEndCompat="@drawable/ic_action_open_episode_list"
android:drawablePadding="10dp"
app:layout_constraintTop_toTopOf="@id/subscription_row_item_thumb"
app:layout_constraintBottom_toBottomOf="@id/subscription_row_item_thumb"
app:layout_constraintStart_toEndOf="@id/subscription_row_item_thumb"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/subscription_row_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:breakStrategy="simple"
android:layout_marginTop="5dp"
android:textSize="14sp"
android:textColor="#A1A0A0"
app:layout_constraintTop_toBottomOf="@id/subscription_row_item_title"
app:layout_constraintStart_toStartOf="@id/subscription_row_item_title"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
要解决此问题,您需要:
wrap_content保持粘贴到文本末尾的宽度drawableEnd,并避免由于app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0"以便将 偏置TextView到开始当TextView内容扩展时,app:layout_constraintEnd_toEndOf="parent"就会有效
将这些应用到TextView:
<TextView
android:id="@+id/subscription_row_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:breakStrategy="simple"
android:layout_marginStart="15dp"
android:textSize="16sp"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0"
app:drawableEndCompat="@drawable/ic_action_open_episode_list"
android:drawablePadding="10dp"
app:layout_constraintTop_toTopOf="@id/subscription_row_item_thumb"
app:layout_constraintBottom_toBottomOf="@id/subscription_row_item_thumb"
app:layout_constraintStart_toEndOf="@id/subscription_row_item_thumb"
app:layout_constraintEnd_toEndOf="parent"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
977 次 |
| 最近记录: |