我正在开发新闻应用程序,但无法对齐textview,因此 它在imageview周围重叠如何正确显示 我正在开发新闻应用程序,但无法对齐textview,因此 它在imageview周围重叠如何正确显示 在我的xml下
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.55"
android:id="@+id/guideline"/>
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/guideline"
app:layout_constraintDimensionRatio="16:9"
android:layout_margin="16dp"
android:id="@+id/articleImage"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="@+id/articleAuthor"
android:layout_marginStart="25dp"
android:layout_marginTop="10dp"
android:text="Placeholder"
android:layout_marginLeft="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/articleAuthor"
app:layout_constraintStart_toStartOf="@id/articleAuthor"
android:layout_marginTop="5dp"
android:maxLines="2"
android:text="Secondary"
android:id="@+id/articleTitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/articleTitle"
app:layout_constraintStart_toStartOf="@id/articleAuthor"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:text="Tertiary"
android:id="@+id/articleTime"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@id/articleTime"
app:layout_constraintBottom_toBottomOf="@id/articleTime"
app:layout_constraintStart_toEndOf="@id/articleTime"
android:layout_marginStart="15dp"
android:id="@+id/articleShare"
android:background="@color/colorWhite"
android:src="@drawable/ic_share"
android:layout_marginLeft="15dp" />
<ImageButton
android:id="@+id/articleFavorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@id/articleShare"
app:layout_constraintBottom_toBottomOf="@id/articleShare"
app:layout_constraintStart_toEndOf="@id/articleShare"
android:layout_marginStart="15dp"
android:background="@color/colorWhite"
android:src="@drawable/ic_bookmark"
android:layout_marginLeft="15dp" />
</android.support.constraint.ConstraintLayout>
下面我要实现的屏幕截图 screenshot I want
答案 0 :(得分:0)
将此属性同时添加到articleAuthor
和articleTitle
TextViews:
app:layout_constraintEnd_toStartOf="@id/guideline"
另外,将这两个相同的视图的layout_width
属性设置为0dp
(即“匹配约束”):
android:layout_width="0dp"
这将导致TextViews与父项的左边缘与准则的右边缘之间的空间完全一样宽。对于小于此宽度的文本,您将获得一行左对齐的文本。对于大于此宽度的文本,您将获得多行左对齐的文本,这些文本在ImageView之前环绕。