【发布时间】:2017-06-29 21:56:19
【问题描述】:
是否可以将一个父项的宽度与另一个父项的宽度相匹配?
我想基本上制作一个表格,其中上部包含一个带有水平 TextViews 的 LinearLayout,其中包含标签,基本上是一行和另一个启用滚动的 LinearLayout,其水平 TextViews 包含在应用程序中更新的值。我希望标签行具有固定宽度的文本视图,并且结果文本视图具有相同的宽度。现在我有 wrap_content 的标签宽度,这就是我想要的。如何使第二个布局中的 TextViews 具有相同的宽度,即使内容将被更改?
简单地说:我希望表亲 textviews 具有相同的宽度,并且一个表亲复制另一个。
下面是我的 .xml 代码。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_dark"
android:orientation="horizontal">
<TextView
android:id="@+id/resultsLabel"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Results" />
<TextView
android:id="@+id/latLabel"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Latitude" />
<TextView
android:id="@+id/longLabel"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Longitude" />
<TextView
android:id="@+id/timeLabel"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Time" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
android:background="@android:color/background_dark">
<TextView
android:id="@+id/resultsValue"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" />
<TextView
android:id="@+id/latValue"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" />
<TextView
android:id="@+id/longValue"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" />
<TextView
android:id="@+id/timeValue"
android:layout_margin="1dp"
android:background="@color/cardview_light_background"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
/>
</LinearLayout>
【问题讨论】:
标签: android xml android-layout android-linearlayout