ConstraintLayout:minWidth和Ellipsize问题

时间:2018-10-18 07:30:28

标签: android textview android-constraintlayout

我有两个相互制约的TextView。 ID为“ list ..._ label”的TextView必须具有以下行为->当ID为“ list ..._ value”的TextView太宽以至于它会截断标签并使其变为椭圆形时,请具有minWidth。现在,minWidth在标签上不起作用,它变为椭圆形,但minWidth不起作用。

当Label达到其minWidth时,id为“ list ..._ value”的TextView也需要进行椭圆处理。

这如何实现?可能是什么问题?

注意:这两个TextView是自定义的,但在命名上变得更加通用。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/Content"
android:background="@drawable/list_item_selector_white">

<include layout="@layout/guidelines" />

<ImageView
    android:id="@+id/list_item_one_line_with_icon_icon"
    android:layout_width="@dimen/list_item_icon_size_large"
    android:layout_height="@dimen/list_item_icon_size_large"
    android:layout_marginBottom="@dimen/du_margin_default"
    android:layout_marginStart="@dimen/du_margin_default"
    android:layout_marginTop="@dimen/du_margin_default"
    android:contentDescription="@string/image_description"
    android:layout_constraintBottom_toBottomOf="parent"
    android:layout_constraintStart_toStartOf="parent"
    android:layout_constraintTop_toTopOf="parent"
    tools:background="@drawable/x_circle_food" />

<TextView
    android:id="@+id/list_item_one_line_with_icon_label"
    style="@style/ConstrainedView.WrappedHeight"
    android:layout_marginBottom="@dimen/du_margin_default"
    android:layout_marginEnd="@dimen/du_margin_default_half"
    android:layout_marginStart="@dimen/du_margin_default_half"
    android:layout_marginTop="@dimen/du_margin_default"
    android:ellipsize="end"
    android:maxLines="1"
    android:minWidth="@dimen/du_list_item_label_min_width"
    android:textColor="@color/du_brown_wcag"
    android:layout_constraintBottom_toBottomOf="parent"
    android:layout_constraintEnd_toStartOf="@+id/list_item_one_line_with_icon_value"
    android:layout_constraintStart_toEndOf="@id/list_item_one_line_with_icon_icon"
    android:layout_constraintTop_toTopOf="parent"
    android:layout_goneMarginRight="@dimen/du_margin_default_half"
    android:typography="@style/L4"
    tools:text="Type something"
    tools:visibility="visible" />

<TextView
    android:id="@id/list_item_one_line_with_icon_value"
    style="@style/Wrapped"
    android:layout_marginBottom="@dimen/du_margin_default"
    android:layout_marginEnd="@dimen/du_margin_default_half"
    android:layout_marginTop="@dimen/du_margin_default"
    android:ellipsize="end"
    android:maxLines="1"
    android:textColor="@color/du_black"
    android:visibility="gone"
    android:layout_constraintBottom_toBottomOf="parent"
    android:layout_constraintEnd_toStartOf="@+id/list_item_one_line_with_icon_arrow"
    android:layout_constraintHorizontal_bias="1"
    android:layout_constraintStart_toEndOf="@id/list_item_one_line_with_icon_label"
    android:layout_constraintTop_toTopOf="parent"
    android:layout_goneMarginRight="@dimen/du_margin_default_half"
    android:typography="@style/L3"
    tools:text="-2 5000,00"
    tools:visibility="visible" />

<ImageView
    android:id="@id/list_item_one_line_with_icon_arrow"
    style="@style/ConstrainedView"
    android:layout_width="@dimen/list_item_arrow_width"
    android:layout_height="@dimen/list_item_arrow_height"
    android:contentDescription="@string/image_description"
    android:scaleType="fitEnd"
    android:src="@drawable/icon_right_arrow_soft_brown"
    android:layout_constraintBottom_toBottomOf="parent"
    android:layout_constraintEnd_toStartOf="@id/guidelines_end"
    android:layout_constraintTop_toTopOf="parent"
    tools:visibility="visible" />

样式

<style name="ConstrainedView">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">0dp</item>
</style>

<style name="Wrapped">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

<style name="ConstrainedView.WrappedHeight">
    <item name="android:layout_height">wrap_content</item>
</style>

0 个答案:

没有答案