gpt4 book ai didi

android - 具有相等行高的表格布局

转载 作者:行者123 更新时间:2023-12-03 15:01:50 26 4
gpt4 key购买 nike

我创建了一个 TableLayout,我希望每一行都具有相同的高度,而不管它的内容如何。
我怎样才能做到这一点?

这是我的代码。每个行元素的宽度相同,但高度不相等。我究竟做错了什么?

 <TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@color/grey"
android:padding="1dip" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/grey" >

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_make"
android:textStyle="bold" />

<TextView
android:id="@+id/carMake"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginLeft="1dip"
android:layout_weight="1"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_detail" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_model"
android:textStyle="bold" />

<TextView
android:id="@+id/carModel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_detail" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_version"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dip"
android:layout_weight="1"
android:background="@color/grey" >

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:layout_marginTop="2dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:layout_marginTop="2dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_mileage"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:layout_marginTop="2dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_engine_capacity"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dip"
android:layout_weight="1"
android:background="@color/grey" >

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_engine_type"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_exterior_color"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_city"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dip"
android:layout_weight="1"
android:background="@color/grey" >

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_transmittion"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_area"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dip"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_registered_city"
android:textStyle="bold" />

<TextView
android:id="@+id/carYear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_horizontal"
android:text="@string/car_year" />
</LinearLayout>
</TableRow>
</TableLayout>

最佳答案

API 11中引入,可以设置android:measureWithLargestChild="true"TableLayoutandroid:layout_weight="1"在每个 TableRow .

关于android - 具有相等行高的表格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13738630/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com