【问题标题】:Android - Equal column width layout for any size textAndroid - 任何大小文本的等列宽度布局
【发布时间】:2015-08-03 12:02:16
【问题描述】:

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

例如,它应该类似于 Play StoreGoogle Keep。我的卡将有 2 行数据。第一个是Title,第二个是Description

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

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

【问题讨论】:

    标签: android android-layout android-tablelayout android-gridlayout


    【解决方案1】:

    如果我足够了解你:

    尝试使用 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。

    【讨论】:

    • 这工作正常,但如果我只有一张卡(或任何奇数张卡)怎么办?
    • 好的.. 通过添加一个空的View 解决了这个问题。现在正在工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-01-12
    • 2018-05-13
    • 2013-12-19
    • 1970-01-01
    • 2016-04-27
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多