【问题标题】:Multiline textview while keeping layout fixed多行文本视图,同时保持布局固定
【发布时间】:2017-04-26 13:55:14
【问题描述】:

我想实现保持固定布局的多行文本视图。 这是预期的输出屏幕 .

这是我得到的输出。

<LinearLayout
    android:id="@+id/layout_product_desc"
    android:layout_width="0dp"
    android:layout_weight="0.75"
    android:layout_height="match_parent"
    android:padding="4dp"
    android:gravity="center"
    android:weightSum="1"
    android:orientation="vertical">
    <LinearLayout
        android:layout_weight="0.90"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:weightSum="1">

        <TextView
            android:id="@+id/txt_product_title"
            style="@style/Appio.Text.Dark.Normal"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="start"
            android:layout_weight="0.40"
            android:maxLines="2"/>
        <TextView
            android:id="@+id/txt_product_subtitle_or_model"
            style="@style/Appio.Text.Dark.Small"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="start"
            android:layout_weight="0.20"
            android:maxLines="1"/>
        <TextView
            android:id="@+id/txt_product_short_description"
            style="@style/Appio.Text.Dark.Small"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="start"
            android:layout_weight="0.20"
            android:maxLines="1"/>
        <TextView
            android:id="@+id/txt_product_availability"
            style="@style/Appio.Text.Dark.Small"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="start"
            android:layout_weight="0.20"
            android:maxLines="1"/>
    </LinearLayout>
    <TextView
        android:id="@+id/txt_product_cost"
        style="@style/Appio.Text.Primary.Normal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:layout_weight="0.10"
        android:maxLines="1"/>
</LinearLayout>

即使我设置了 maxLine 并分配了 weight 属性,布局并没有保持固定。还有一些“Out of Stock”,如图 2 所示。我该如何解决这个问题?

【问题讨论】:

    标签: android textview multiline android-layout-weight


    【解决方案1】:

    如果您想使用权重,请将 txt_product_cost 高度替换为 0dp。

    <TextView
        android:id="@+id/txt_product_cost"
        style="@style/Appio.Text.Primary.Normal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="start"
        android:layout_weight="0.10"
        android:maxLines="1"/>
    

    这应该可以解决您的问题

    【讨论】:

      【解决方案2】:

      您应该尝试删除第一个 LinearLayout 中 TextViwes 的 android:layout_weight="0.20" 并将 android:layout_height 更改为 wrap_content

      【讨论】:

        【解决方案3】:

        你不能在这里依赖 layout_weight 。将 layout_height 设置为“wrap_content”

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-01-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-02
          • 1970-01-01
          相关资源
          最近更新 更多