gpt4 book ai didi

android - TableLayout 拒绝 match_parent

转载 作者:搜寻专家 更新时间:2023-11-01 09:31:49 25 4
gpt4 key购买 nike

我有一个 xml 布局,用作 ListView 中的一个项目。问题是:当它被添加到那里时,项目的宽度不会拉伸(stretch)到 match_parent,而是包裹内容。它在 ListView 中使用,因此其宽度需要为 match_parent。我一直在通过 stackoverflow 阅读它,尝试所有可用的解决方案,但结果为零:layout_weight 设置为 1 对我的布局没有任何影响,拉伸(stretch)列给了我最好的结果宽度,但就布局本身而言,它惨遭失败。

这里有什么可以做的吗?

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">

<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">

<CheckBox
android:id="@+id/trackCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:clickable="false"
android:duplicateParentState="true" />

<TextView
android:id="@+id/trackNumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="00."
android:textColor="@android:color/black"
android:textSize="18sp" />

<TextView
android:id="@+id/trackTitleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_weight="1"
android:text="Title"
android:textColor="@android:color/black"
android:textSize="18sp" />
</TableRow>

<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">

<TextView
android:id="@+id/trackArtistText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_weight="1"
android:text="Artist" />
</TableRow>
</TableLayout>

最佳答案

添加android:stretchColumns="*" TableLayout

中的属性

android:stretchColumns

The zero-based index of the columns to stretch. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored. You can stretch all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:descendantFocusability="blocksDescendants">

.....

</TableLayout>

希望这会有所帮助。

关于android - TableLayout 拒绝 match_parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46560243/

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