android - Replace GridLayout with LinearLayout -
i have gridlayout displays calculator screen. looks nice on many devices utterly fails on small displays , big displays. there bug in gridlayout implementation google not working on it. can see details in half year old question , accepted answer: gridlayout collapses on small display
i tried reimplement layout. started new constraintlayout without luck. linearlayout quite close failed stretch individual cells. not fill available space. when change width wrap_content match_parent, layout breaks totally.
all source code , sample application available @ https://github.com/literakl/calctrouble.
current linear layout
gridlayout when works
broken gridlayout on nexus 5
broken gridlayout on nexus s
layout source code
<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 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 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 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 0, backspace , / --> <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 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> how can achieve desired work on devices?
make button's width 0dp, height match_parent , layout_weight 1 in below sample single row
<!-- row 7-9,+ --> <linearlayout android:layout_height="0dp" android:layout_weight="1" android:weightsum ="4" android:orientation="horizontal" android:layout_width="match_parent"> <button android:id="@+id/digit7" android:text="7" style="@style/keypadleftbutton" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" tools:ignore="hardcodedtext" /> <button android:id="@+id/digit8" android:text="8" style="@style/keypadbutton" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" tools:ignore="hardcodedtext" /> <button android:id="@+id/digit9" android:text="9" style="@style/keypadbutton" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" tools:ignore="hardcodedtext" /> <button android:id="@+id/buttonplus" android:text="+" style="@style/keypadfunctionrightbutton" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" tools:ignore="hardcodedtext" /> </linearlayout> </linearlayout> 



Comments
Post a Comment