首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在约束布局中将文本视图放置在图像视图的右侧,而不重叠并覆盖整个宽度

如何在约束布局中将文本视图放置在图像视图的右侧,而不重叠并覆盖整个宽度
EN

Stack Overflow用户
提问于 2021-11-01 11:33:32
回答 2查看 46关注 0票数 0

我正在尝试将文本视图放在图像视图的右侧。虽然我能够做到这一点,但当我给出match parent to text视图时,我面临着问题。我希望文本覆盖其余区域,但当我使用match parent时,它会与左侧的图像视图重叠。以下是我的代码

代码语言:javascript
复制
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/margin_default"
    android:layout_marginTop="12dp"

    android:layout_marginEnd="@dimen/margin_default"
    android:layout_marginBottom="12dp">


    <ImageView
        android:id="@+id/effective_warnings_card_icon"
        android:layout_width="48dp"
        android:layout_height="0dp"
        android:focusable="false"

        android:importantForAccessibility="no"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="@id/effective_warnings_card_text"
        app:srcCompat="@drawable/account_unavailable_image"
        tools:src="@tools:sample/avatars" />

    <TextView
        android:id="@+id/effective_warnings_card_text"
        style="@style/TextAppearance.TSBApp20.Body.Regular"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:text="aggfgffh"

        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintLeft_toRightOf="@+id/effective_warnings_card_icon"
        app:layout_constraintStart_toEndOf="@+id/effective_warnings_card_icon"
        app:layout_constraintTop_toTopOf="parent" />


    <!--            <ImageView-->
    <!--                android:id="@+id/effective_warnings_card_icon"-->

    <!--                        android:layout_width="48dp"-->
    <!--                        android:layout_height="48dp"-->
    <!--                        android:layout_marginStart="@dimen/margin_default"-->
    <!--                        app:srcCompat="@drawable/account_unavailable_image"-->
    <!--                        android:importantForAccessibility="no"-->
    <!--                        android:focusable="false"-->
    <!--                        app:layout_constraintTop_toTopOf="parent"-->
    <!--                        app:layout_constraintBottom_toBottomOf="parent"-->
    <!--                        app:layout_constraintStart_toStartOf="parent"-->
    <!--                        tools:src="@tools:sample/avatars"-->
    <!--                            />-->
    <!--            <TextView-->
    <!--                android:id="@+id/effective_warnings_card_text"-->
    <!--                style="@style/TextAppearance.TSBApp20.Body.Regular"-->
    <!--                android:layout_width="wrap_content"-->
    <!--                android:layout_height="wrap_content"-->
    <!--android:text="afafafaffafa"-->
    <!--                app:layout_constraintEnd_toEndOf="parent"-->
    <!--                app:layout_constraintStart_toEndOf="@+id/effective_warnings_card_icon"-->
    <!--                app:layout_constraintBottom_toBottomOf="@+id/effective_warnings_card_icon"-->
    <!--                app:layout_constraintTop_toTopOf="@+id/effective_warnings_card_icon"-->
    <!--                />-->


</androidx.constraintlayout.widget.ConstraintLayout>

在添加的图像中,您可以看到文本以黑色布局覆盖图像。如何做到这一点?

EN

回答 2

Stack Overflow用户

发布于 2021-11-01 12:04:39

您必须将0dp设置为TextView

代码语言:javascript
复制
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/margin_default"
    android:layout_marginTop="12dp"
    android:layout_marginEnd="@dimen/margin_default"
    android:layout_marginBottom="12dp">

    <ImageView
            android:id="@+id/effective_warnings_card_icon"
            android:layout_width="48dp"
            android:layout_height="0dp"
            android:focusable="false"

            android:importantForAccessibility="no"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="@id/effective_warnings_card_text"
            app:srcCompat="@drawable/account_unavailable_image"
            tools:src="@tools:sample/avatars" />

        <TextView
            android:id="@+id/effective_warnings_card_text"
            style="@style/TextAppearance.TSBApp20.Body.Regular"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:text="aggfgffh"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/effective_warnings_card_icon"
            app:layout_constraintStart_toEndOf="@+id/effective_warnings_card_icon"
            app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
票数 1
EN

Stack Overflow用户

发布于 2021-11-01 12:28:29

TextView中删除app:layout_constraintLeft_toRightOf="@+id/effective_warnings_card_icon"

还要从ImageView中删除app:layout_constraintEnd_toEndOf="@id/effective_warnings_card_text"

0dp宽度设置为TextView

代码语言:javascript
复制
    <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/margin_default"
    android:layout_marginTop="12dp"
    android:layout_marginEnd="@dimen/margin_default"
    android:layout_marginBottom="12dp">

    <ImageView
            android:id="@+id/effective_warnings_card_icon"
            android:layout_width="48dp"
            android:layout_height="0dp"
            android:focusable="false"

            android:importantForAccessibility="no"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/account_unavailable_image"
            tools:src="@tools:sample/avatars" />

        <TextView
            android:id="@+id/effective_warnings_card_text"
            style="@style/TextAppearance.TSBApp20.Body.Regular"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:text="aggfgffh"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@+id/effective_warnings_card_icon"
            app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69796356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档