Android 如何将多个视图的宽度设置为其中最大的内容宽度?(动态)

Android 如何将多个视图的宽度设置为其中最大的内容宽度?(动态),android,android-layout,Android,Android Layout,当我使用静态定义的布局时,我可以通过将wrap\u content设置为LinearLayoutlayout\u width并将match\u parent设置为其子级layout\u width 例如,以下XML布局定义: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_he

当我使用静态定义的布局时,我可以通过将
wrap\u content
设置为
LinearLayout
layout\u width
并将
match\u parent
设置为其子级
layout\u width
例如,以下XML布局定义:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#f88"
    android:orientation="vertical" >

    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#8f8"
        android:text="Smaller"
        />

    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#8f8"
        android:text="I'm a bigger view"
        />
</LinearLayout>

似乎它没有“所需宽度”的概念,并强制其父对象拉伸。

只需将“分隔器”的视图类从
视图更改为
文本视图即可解决此问题。后者并不试图占据所有可用空间。但如果有更优雅的解决方案,这仍然很有趣(我怀疑使用TextView来实现这一目的有点过火,效率也不高)



请发布用于动态添加视图的代码。@DavidWasser确定。只需要在…嗯…之前把它剥掉一点。在滚动另一个最小示例后,问题消失了。我会尝试找出我最初的方法是怎么回事,如果不是很愚蠢,就发布为答案(否则-删除它)@DavidWasser似乎代码不是问题。我在问答中发布了更多细节。
<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#777" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#777" />