GridLayout показывает только первый столбец

#android

#Android

Вопрос:

Я пытаюсь более 2 часов выяснить, почему в моем сеточном описании отображается только первый столбец. Я экспериментировал с различными вариантами, такими как layout_weight и layout_columnWeight

 <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="4dp"
    android:orientation="vertical"
    tools:layout_editor_absoluteX="4dp"
    tools:layout_editor_absoluteY="4dp">

    <GridLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="3">

        <TextView
            android:layout_width="0dp"
            android:layout_row="0"
            android:layout_column="0"
            android:layout_columnSpan="2"
            android:text="Type:"
            android:textSize="18sp"
            android:layout_columnWeight="1"/>

        <Spinner
            android:layout_width="0dp"
            android:id="@ id/spinnerEvpRecordType"
            android:layout_row="0"
            android:layout_column="1"
            android:layout_columnSpan="1"
            android:clickable="false"
            android:entries="@array/evp_record_types"
            android:layout_columnWeight="1"/>
</GridLayout>
</androidx.cardview.widget.CardView>
  

Ответ №1:

Я думаю, проблема в том, что вы явно помещаете свой Spinner внутри второго столбца, в то время TextView как он охватывает первые два, поэтому они перекрываются. Попробуйте удалить android:layout_column свойство в обоих TextView и Spinner . Но вам все равно придется работать с весами столбцов, чтобы достичь желаемой пропорции.