【问题标题】:Align row texts in a listview在列表视图中对齐行文本
【发布时间】:2010-11-09 13:43:39
【问题描述】:

我的列表视图的行有 3 个文本。我想要做的是垂直对齐所有行文本。我尝试使用该行的 TableLayout 视图,并将第一个和第三个单元格的宽度设置为常量。由于移植问题,我不太喜欢使用常量。是否可以在没有其他方式的情况下对齐这些文本?这是布局:

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

    <TextView
            android:id="@+id/ingredient_amount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

    <com.one2snap.littlechef.android.main.ui.views.AmienneTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ingredient_title" />

</LinearLayout>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    您可以使用 LinearLayout 并将权重应用于每个 Text 视图。如果您给每个文本赋予 1 的权重,那么它们将平均占据屏幕的三分之一。如果你给一个文本赋予 2 的权重,而给其他文本赋予 1 的权重,那么 2 将占据屏幕的一半,另外两个将使用第四个,等等。See here under LinearLayout for more info.

    【讨论】:

    • 使用 LinearLayout 和 weight 没有帮助。它使用剩余空间,而不是绝对空间。所以第二个和第三个文本视图不能对齐。
    • 使用LinearLayout和权重意味着使用额外的空间,所以它不会创建宽度相等的视图。
    • 我必须说我很惊讶没有更多关于如何做这种事情的意见。在我的工作中,我遇到过许多需要以简洁的表格格式显示数据行的情况,但从我能够发现的关于该主题的文献数量来看,你会认为没有人在 Android 设备上这样做.
    猜你喜欢
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 2015-07-01
    相关资源
    最近更新 更多