У меня есть GridLayout
, который отображает экран калькулятора. Он выглядит очень хорошо на многих устройствах, но совершенно не работает на маленьких дисплеях и даже на некоторых больших дисплеях. Есть ошибка в реализации GridLayout, но Google не работает над ней. Вы можете увидеть подробности в моем вопросе полугодовой давности и принятом ответе: GridLayout сворачивается на маленьком экране
Я попытался заново реализовать свой макет. Начал с нового ConstraintLayout
без везения. LinearLayout
довольно близко, но растянуть отдельные ячейки мне не удалось. Они не заполняют доступное пространство. Когда я меняю ширину с wrap_content
на match_parent
, макет полностью ломается.
Весь исходный код и образец приложения доступны по адресу https://github.com/literakl/CalcTrouble.
Текущая линейная компоновка
GridLayout, когда он работает
Сломанный GridLayout на Nexus 5
Сломанный GridLayout на Nexus S
Исходный код макета
<LinearLayout
android:id="@+id/calc_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/bg_calc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--Display row-->
<TextView
android:id="@+id/assignment"
android:text="50 + 40 = 90"
style="@style/Formula"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="@dimen/calc_display_height"
tools:ignore="HardcodedText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- row with 7-9,+ -->
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent">
<Button
android:id="@+id/digit7"
android:text="7"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit8"
android:text="8"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit9"
android:text="9"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonPlus"
android:text="+"
style="@style/KeypadFunctionRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</LinearLayout>
<!--row with 4-6, - -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:id="@+id/digit4"
android:text="4"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit5"
android:text="5"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit6"
android:text="6"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonMinus"
android:text="-"
style="@style/KeypadFunctionRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</LinearLayout>
<!--row with 1-3, * -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:id="@+id/digit1"
android:text="1"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit2"
android:text="2"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/digit3"
android:text="3"
style="@style/KeypadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonMultiply"
android:text="\u22C5"
style="@style/KeypadFunctionRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</LinearLayout>
<!--row with 0, backspace and / -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:id="@+id/digit0"
android:text="0"
style="@style/KeypadLeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonBackspace"
android:text="←"
style="@style/KeypadFunctionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_columnSpan="2"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/buttonDivide"
android:text=":"
style="@style/KeypadFunctionRightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_rowWeight="1"
app:layout_columnWeight="1"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<!--row with button submit -->
<Button
android:id="@+id/buttonSubmit"
android:text="@string/action_next_formula"
style="@style/KeypadNextButton"
android:layout_width="match_parent"
android:layout_height="@dimen/calc_next_height"
app:layout_gravity="fill_horizontal"/>
</LinearLayout>
Как добиться желаемого внешнего вида, который будет работать на всех устройствах?