Я пытаюсь создать TableLayout
с 3 столбцами и 4 строками, и мне нужно, чтобы все строки имели одинаковую высоту.TableLayout - TableRows с одинаковым layout_weight не имеют одинаковой высоты
Я пробовал много вещей, но результат всегда один и тот же. Третья строка, которая имеет только два TextViews, всегда заканчивается тем, что имеет строку с меньшей высотой.
Это XML для макета:
<TableLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4">
<TableRow
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:weightSum="7">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_weight="2"
android:text="Tipo Venta"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
<Spinner
android:id="@+id/tipoVentaSpinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@color/secondary_text"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:weightSum="7">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_weight="2"
android:text="Tipo Pago"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
/>
<Spinner
android:id="@+id/tipoPagoSpinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@color/secondary_text"
android:touchscreenBlocksFocus="true"/>
</TableRow>
<TableRow
android:id="@+id/clienteRow"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:weightSum="7">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_weight="2"
android:text="Cliente"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
<TextView
android:id="@+id/clienteTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@color/secondary_text"/>
</TableRow>
<TableRow
android:id="@+id/rucRow"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:weightSum="7">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_weight="2"
android:text="RUC"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
<EditText
android:id="@+id/rucEditText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:inputType="number"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@color/secondary_text"/>
<ImageButton
android:id="@+id/buscarClieImageButton"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@android:drawable/ic_menu_search"/>
</TableRow>
</TableLayout>
TableLayout
описанный выше, является частью другого макета, поэтому указать layout_weight
из 4 для него.
У вас есть идеи, что вызывает подобное поведение?
Спасибо.
Возможно, вам нужно установить высоту для каждой строки, иначе это будет высота содержимого. Попробуйте match_parent для всех элементов в TR и установите каждый TR на фиксированный dp. Также убедитесь, что элементы в TR не имеют никаких нежелательных верхних и нижних полей, которые приводят к увеличению высоты. – Onimusha
Привет, почему бы вам не дать никаких отзывов? Есть ли еще какая-то проблема, если так любезно рассказать. –
Извините @ShreeKrishna Я догнал кое-что на работе. TBH ваше решение было единственным, что было близко к тому, что я хочу достичь (похоже, что все строки одного размера, но я не могу точно сказать) Не могли бы вы объяснить мне, как это работает? – Axel