【问题标题】:Expanding a TextView within a TableLayout在 TableLayout 中展开 TextView
【发布时间】:2018-12-21 14:32:39
【问题描述】:

我有一个 TableLayout,其中每个 TableRow 包含一个 ImageView 和一个 TextView。如果它们的内容不适合一行,我想让 TextViews 扩展到多行。

我尝试了许多不同的属性设置,例如将 TextView 设置为 wrap_content、maxLines、scrollHorizo​​ntal = false,并且没有省略号。我也尝试将 TableView 设置为 wrap_content 但没有运气。我在网上能找到的一切似乎都是关于没有嵌套在 TableLayout 中的 TextView,所以我不知道 TableLayout 设置是否会干扰其他答案。我能找到的最接近的相关问题是here,但它对我不起作用。

下面是我的 TableLayout 的 XML:

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:gravity="center_vertical|start"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp">

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.15"
            app:srcCompat="@drawable/ic_info_24px" />

        <TextView
            android:id="@+id/AdditionalInfo"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_span="3"
            android:layout_weight="0.85"
            android:gravity="center_vertical|start"
            android:text="Additional Info that can potentially be too much for one line"
            android:textSize="16sp" />

    </TableRow>

</TableLayout>

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    尝试添加属性 android:inputType="textMultiLine" 到文本视图。并在属性 android:layout_height 中将“match_parent”更改为“wrap_content”。

    【讨论】:

    • 我想说我尝试了 textMultiLane,但后来意识到我没有将高度设置为 wrap_content。谢谢,它有效!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 1970-01-01
    相关资源
    最近更新 更多