Android - 任意大小文本的等宽布局

Android - Equal column width layout for any size text

我对 android 很陌生。我想以表格形式显示卡片。我想要 2 列,它们的长度应该完全相等(即使其中一列中的内容大小增加了)。

例如,它应该像 Play StoreGoogle Keep。我的卡将有 2 行数据。第一个用于 标题,第二个用于 描述

我尝试了很多布局; TableLayoutGridLayout 等,但实际上都没有用。最后我读了 this SO post 但如果我的卡片上的文字大小增加它就不起作用了。

知道如何做到这一点吗?如果 Description 文本在末尾省略号,这将是一个奖励。

如果我足够了解你:

尝试使用 LinearLayout 并设置布局内项目的 layout_weight。所以你会有这样的东西:

<LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal">

    <Card
        android:id="@+id/card1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <Card
        android:id="@+id/card2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

</LinearLayout>

然后,如果您可能希望在列中包含多个内容,只需将这些卡片项目添加为垂直方向的 LinearLayouts。