首页 > 解决方案 > 约束布局包装文本视图,但约束宽度太长而无法让其他视图可见

问题描述

我必须设计这个布局。图标应该粘在textview.

在此处输入图像描述

这是我尝试过的,看起来正是需要的。

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="@dimen/padding_m"
        android:paddingTop="@dimen/padding_s"
        android:paddingEnd="@dimen/padding_m"
        android:paddingBottom="@dimen/padding_s"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:id="@+id/title_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@id/more_options"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <TextView
                android:id="@+id/active_group_name"
                style="@style/AppbarTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:maxLines="1"
                app:layout_constrainedWidth="true"
                tools:text="Ranjan Malav" />

            <FrameLayout
                android:id="@+id/account_option_icon_container"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/margin_xs"
                android:background="@drawable/circle_background_36dp">

                <ImageView
                    android:id="@+id/account_option_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    app:srcCompat="@drawable/ic_outline_settings_24" />
            </FrameLayout>

        </LinearLayout>

        <ImageView
            android:id="@+id/more_options"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_baseline_more_vert_24"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

在此处输入图像描述

但是当文本很长时,设置图标会被隐藏。 在此处输入图像描述

我怎样才能给图标优先级并让它占据空间,然后 textview 应该将自己包裹在剩余的空间中?

标签: androidandroid-layoutandroid-constraintlayout

解决方案


在 textview 之前创建你的 ImageView


推荐阅读