My last of column of gridlayout going out of screen - android-studio

I created gridlayout of 3 columns and it's doing great with large screen phone but with small screen phone there is problem last column going out of screen.
I also tried to set column_weight="1" but it's even worse.
Please help me I stuck here for many of days and tried so many things but it doesn't help.
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alignmentMode="alignMargins"
android:columnCount="3"
android:rowCount="8">
<TextView
android:layout_row="0"
android:layout_column="0"
android:padding="10dp"
android:text="#string/sub"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_row="0"
android:layout_column="1"
android:layout_marginStart="50dp"
android:padding="10dp"
android:text="#string/credit"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_row="0"
android:layout_column="2"
android:layout_marginStart="50dp"
android:padding="10dp"
android:text="#string/grade"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_row="1"
android:layout_column="0"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:text="#string/m2"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="2"
android:layout_column="0"
android:layout_marginStart="10dp"
android:padding="10dp"
android:text="#string/dsa"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="3"
android:layout_column="0"
android:layout_marginStart="10dp"
android:padding="10dp"
android:text="#string/dsalab"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="4"
android:layout_column="0"
android:layout_marginStart="10dp"
android:padding="10dp"
android:text="#string/vee"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="5"
android:layout_column="0"
android:layout_marginStart="10dp"
android:padding="10dp"
android:text="#string/eeb"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="6"
android:layout_column="0"
android:layout_marginStart="10dp"
android:padding="10dp"
android:text="#string/dms"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="7"
android:layout_column="0"
android:layout_marginStart="10dp"
android:padding="10dp"
android:text="#string/anel"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="1"
android:layout_column="1"
android:layout_marginStart="70dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:text="4"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="2"
android:layout_column="1"
android:layout_marginStart="70dp"
android:padding="10dp"
android:text="3"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="3"
android:layout_column="1"
android:layout_marginStart="70dp"
android:padding="10dp"
android:text="1"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="4"
android:layout_column="1"
android:layout_marginStart="70dp"
android:padding="10dp"
android:text="3"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="5"
android:layout_column="1"
android:layout_marginStart="70dp"
android:padding="10dp"
android:text="3"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="6"
android:layout_column="1"
android:layout_marginStart="70dp"
android:padding="10dp"
android:text="3"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:layout_row="7"
android:layout_column="1"
android:layout_marginStart="70dp"
android:padding="10dp"
android:text="3"
android:textColor="#4C4C4C"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:layout_row="1"
android:layout_column="2"
android:layout_width="60dp"
android:background="#drawable/round_box"
android:layout_marginStart="63dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:inputType="text"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:layout_row="2"
android:layout_column="2"
android:layout_width="60dp"
android:background="#drawable/round_box"
android:layout_marginStart="63dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:inputType="text"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:layout_row="3"
android:layout_column="2"
android:layout_width="60dp"
android:background="#drawable/round_box"
android:layout_marginStart="63dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:inputType="text"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:layout_row="4"
android:layout_column="2"
android:layout_width="60dp"
android:background="#drawable/round_box"
android:layout_marginStart="63dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:inputType="text"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:layout_row="5"
android:layout_column="2"
android:layout_width="60dp"
android:background="#drawable/round_box"
android:layout_marginStart="63dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:inputType="text"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:layout_row="6"
android:layout_column="2"
android:layout_width="60dp"
android:background="#drawable/round_box"
android:layout_marginStart="63dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:inputType="text"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:layout_row="7"
android:layout_column="2"
android:layout_width="60dp"
android:background="#drawable/round_box"
android:layout_marginStart="63dp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:inputType="text"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
</GridLayout>

Related

Align anchored widgets to fill whitespace in Android Studio

I am new at Android development and I am struggling with the following.
I am building a simple calculator application with a 4x4 keypad.
All the buttons are anchored from right to left and bottom to top. Baselines are used as well.
The top-left button will be anchored to the TextView above.
I need the buttons to keep the square size I gave them, but also be aligned properly so they fill the white space remaining to the right.
I tried anchoring the right side of the right-edge button to the right side of the TextView, but the intermediate column spacing is not divided in equal portions.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="#+id/txtResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:inputType="numberSigned|number|numberDecimal"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/txtNewNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="numberSigned|numberDecimal"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/txtResult" />
<Button
android:id="#+id/btn1"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:text="1"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="#+id/txtNewNumber"
app:layout_constraintTop_toBottomOf="#+id/txtNewNumber" />
<Button
android:id="#+id/btn2"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="2"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn1"
app:layout_constraintStart_toEndOf="#+id/btn1" />
<Button
android:id="#+id/btn3"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="3"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn2"
app:layout_constraintStart_toEndOf="#+id/btn2" />
<Button
android:id="#+id/btn4"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:text="4"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="#+id/btn1"
app:layout_constraintTop_toBottomOf="#+id/btn1" />
<Button
android:id="#+id/btn5"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="5"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn4"
app:layout_constraintStart_toEndOf="#+id/btn4" />
<Button
android:id="#+id/btn6"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="6"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn5"
app:layout_constraintStart_toEndOf="#+id/btn5" />
<Button
android:id="#+id/btn7"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="8"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn8"
app:layout_constraintStart_toEndOf="#+id/btn8" />
<Button
android:id="#+id/btn8"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:text="7"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="#+id/btn4"
app:layout_constraintTop_toBottomOf="#+id/btn4" />
<Button
android:id="#+id/btn9"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="9"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn7"
app:layout_constraintStart_toEndOf="#+id/btn7" />
<Button
android:id="#+id/btnPlus"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="+"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn3"
app:layout_constraintStart_toEndOf="#+id/btn3" />
<Button
android:id="#+id/btnMinus"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="-"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn6"
app:layout_constraintStart_toEndOf="#+id/btn6" />
<Button
android:id="#+id/btnMultiply"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="*"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn9"
app:layout_constraintStart_toEndOf="#+id/btn9" />
<Button
android:id="#+id/btnDot"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:text="."
android:textSize="24sp"
app:layout_constraintStart_toStartOf="#+id/btn8"
app:layout_constraintTop_toBottomOf="#+id/btn8" />
<Button
android:id="#+id/btn0"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="0"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btnDot"
app:layout_constraintStart_toEndOf="#+id/btnDot" />
<Button
android:id="#+id/btnEquals"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="="
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn0"
app:layout_constraintStart_toEndOf="#+id/btn0" />
<Button
android:id="#+id/btnDivision"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="/"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btnEquals"
app:layout_constraintStart_toEndOf="#+id/btnEquals" />
</androidx.constraintlayout.widget.ConstraintLayout>
To spread out the buttons like you want, you can use ConstraintLayout CHAIN_SPREAD_INSIDE chains.
Here is your XML with the first row placed into a horizontal chain. See how the views spread out between the leftmost and rightmost anchor points? (I have set the rightmost anchor to the end of the result view.)
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/txtResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:inputType="numberSigned|number|numberDecimal"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/txtNewNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="numberSigned|numberDecimal"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/txtResult" />
<Button
android:id="#+id/btn1"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:text="1"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="#id/btn2"
app:layout_constraintStart_toStartOf="#+id/txtNewNumber"
app:layout_constraintTop_toBottomOf="#+id/txtNewNumber"
app:layout_constraintHorizontal_chainStyle="spread_inside" />
<Button
android:id="#+id/btn2"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="2"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn1"
app:layout_constraintEnd_toStartOf="#id/btn3"
app:layout_constraintStart_toEndOf="#+id/btn1" />
<Button
android:id="#+id/btn3"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="3"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn2"
app:layout_constraintEnd_toStartOf="#id/btnPlus"
app:layout_constraintStart_toEndOf="#+id/btn2" />
<Button
android:id="#+id/btnPlus"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="+"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn3"
app:layout_constraintEnd_toEndOf="#id/txtResult"
app:layout_constraintStart_toEndOf="#+id/btn3" />
<Button
android:id="#+id/btn4"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:text="4"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="#+id/btn1"
app:layout_constraintTop_toBottomOf="#+id/btn1" />
<Button
android:id="#+id/btn5"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="5"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn4"
app:layout_constraintStart_toEndOf="#+id/btn4" />
<Button
android:id="#+id/btn6"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="6"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn5"
app:layout_constraintStart_toEndOf="#+id/btn5" />
<Button
android:id="#+id/btn7"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="8"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn8"
app:layout_constraintStart_toEndOf="#+id/btn8" />
<Button
android:id="#+id/btn8"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:text="7"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="#+id/btn4"
app:layout_constraintTop_toBottomOf="#+id/btn4" />
<Button
android:id="#+id/btn9"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="9"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn7"
app:layout_constraintStart_toEndOf="#+id/btn7" />
<Button
android:id="#+id/btnMinus"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="-"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn6"
app:layout_constraintStart_toEndOf="#+id/btn6" />
<Button
android:id="#+id/btnMultiply"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="*"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn9"
app:layout_constraintStart_toEndOf="#+id/btn9" />
<Button
android:id="#+id/btnDot"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:text="."
android:textSize="24sp"
app:layout_constraintStart_toStartOf="#+id/btn8"
app:layout_constraintTop_toBottomOf="#+id/btn8" />
<Button
android:id="#+id/btn0"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="0"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btnDot"
app:layout_constraintStart_toEndOf="#+id/btnDot" />
<Button
android:id="#+id/btnEquals"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="="
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btn0"
app:layout_constraintStart_toEndOf="#+id/btn0" />
<Button
android:id="#+id/btnDivision"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:text="/"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="#+id/btnEquals"
app:layout_constraintStart_toEndOf="#+id/btnEquals" />
</androidx.constraintlayout.widget.ConstraintLayout>
The other rows will work the same way.

Use Relative layout with Scrollable Constraint layout to achieve a freeze panes effect

I am pretty new to Android Studio, so please forgive any thing which may have been obvious but I did not pick up.
I would like help in the below situation -
I have setup two layouts:
Relative Layout & a Constraint Layout (which is nested in ScrollView).
I wanted to keep some views to be visible all the time, so I put them in a Relative Layout. I put all other views in a constraint layout which is scrollable, since the number of elements do not fit in the screen.
I am trying to get the same effect which you get when you freeze the top row of an excel worksheet.
I tried to adjust the layout height property of the Constraint Layout but I can't seem to get it right. What I want is to anchor my Constraint Layout below the Relative Layout.
I have attached my code.
Thanks a lot in advance,
Regards,
Ravi.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.android.raviagl.netlandingcostcalculate.MainActivity">
<TextView
android:id="#+id/sap"
android:layout_width="120dp"
android:layout_height="72dp"
android:layout_marginLeft="16dp"
android:layout_toRightOf="#id/nlc"
android:gravity="center_vertical"
android:text="SAP"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp" />
<Button
android:id="#+id/reset_all"
android:layout_width="120dp"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="13dp"
android:text="Reset" />
<TextView
android:id="#+id/nlc"
android:layout_width="120dp"
android:layout_height="72dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:gravity="center_vertical"
android:text="NLC"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraint_layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteY="81dp">
<EditText
android:id="#+id/dp"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="88dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/allowance"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dp" />
<EditText
android:id="#+id/gst"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/allowance" />
<EditText
android:id="#+id/slab"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/gst" />
<RadioGroup
android:id="#+id/slab_radio_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/slab">
<RadioButton
android:id="#+id/radio_slab_value"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:checked="true"
android:text="Use Fixed Amount"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
<RadioButton
android:id="#+id/radio_slab_percent"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:text="Use SAP Percent"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
</RadioGroup>
<EditText
android:id="#+id/sell_through"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/slab" />
<EditText
android:id="#+id/sell_out"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sell_through" />
<EditText
android:id="#+id/display"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sell_out" />
<RadioGroup
android:id="#+id/display_radio_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/display">
<RadioButton
android:id="#+id/radio_display_value"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:checked="true"
android:text="Use Fixed Amount"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
<RadioButton
android:id="#+id/radio_display_percent"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:text="Use SAP Percent"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
</RadioGroup>
<EditText
android:id="#+id/tie_up"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/display" />
<EditText
android:id="#+id/handling"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tie_up" />
<EditText
android:id="#+id/cash_discount"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/handling" />
<TextView
android:id="#+id/d_dp"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="8dp"
android:text="DP"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_allowance"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Allowance"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/allowance"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_gst"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="GST"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/gst"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_slab"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Slab"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/slab"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_sell_through"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Sell Through"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/sell_through"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_sell_out"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Sell Out"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/sell_out"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_display"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Display"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/display"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_tie_up"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Tie UP"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/tie_up"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_handling"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Handling"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/handling"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_cash_discount"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Cash Discount"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/cash_discount"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
</RelativeLayout>
There are a few options to consider here but I think the one that requires the least amount of refactoring your layout is this:
Add android:layout_below attribute to your ScrollView and position it under one the views that are fixed. It doesn't matter which one as long as they are the same height:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/sap">
Decrease (or remove) the top margin from the EditText with the ID android:id="#+id/dp"to eliminate unnecessary space on the top.
All that being said since you are using fixed widths for all the views in your layout you might run into some problems with displaying it on different screen sizes. For example the three fixed views on the top might overlap each other if there is not enough horizontal space. This could possibly be resolved by using other layouts (such as ConstraintLayout or LinearLayout) as root and/or not using fixed widths. However, this would require much more refactoring that the solution above.

How to resize table of buttons to work fine with all phones

Hello i'am trying to make a Tictactoy game my problem is in the layout design how to make it when the screen grows bigger the table and buttons inside become grow bigger and When the screen is smaller, the table and buttons inside become smaller not only the table
There is any way to fix this ?
The Correct one(my sccren)
The wrong one(when i change it to a smaller sccren)
,
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical"
tools:context="com.example.pc.tictactoyv1.act11">
<TableLayout
android:id="#+id/Table"
android:layout_width="357dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.42"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2"
app:layout_constraintVertical_bias="0.356">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="#+id/Btn1"
android:layout_width="110dp"
android:layout_height="128dp"
android:layout_marginRight="5dp"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
tools:ignore="ButtonStyle" />
<Button
android:id="#+id/Btn2"
android:layout_width="110dp"
android:layout_height="128dp"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
android:textStyle="bold" />
<Button
android:id="#+id/Btn3"
android:layout_width="110dp"
android:layout_height="128dp"
android:layout_marginLeft="5dp"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp" />
android:textSize="24sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:weightSum="3">
<Button
android:id="#+id/Btn4"
android:layout_width="90dp"
android:layout_height="128dp"
android:layout_marginRight="5dp"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp" />
<Button
android:id="#+id/Btn5"
android:layout_width="110dp"
android:layout_height="128dp"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp" />
<Button
android:id="#+id/Btn6"
android:layout_width="110dp"
android:layout_height="128dp"
android:layout_marginLeft="5dp"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp" />
</TableRow>
</TableLayout>
You have several options:
ConstraintLayout with percentage guidelines
nested vertical and horizontal LinearLayouts with weights
creating a CustomView that handles the sizes in onMeasure
ImageViews with white rectangular background, set to fitXY and adjustViewBounds = true
These are just some options I came up with at the top of my head, there are many more. Pick whatever suits your needs best. For beginners probably the way with the ConstraintLayout is the easiest.
I still don't exactly know what you want, but I added an example, that scales evenly, using ConstraintLayout and chains. Also checkout the constraintDimensionRatio whick makes everything square. You might want to checkout Constraint Layout How To
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal">
</LinearLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/linearLayout2">
<Button
android:id="#+id/Btn4"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toTopOf="#+id/Btn7"
app:layout_constraintEnd_toStartOf="#+id/Btn5"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Btn1" />
<Button
android:id="#+id/Btn9"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/Btn8"
app:layout_constraintTop_toBottomOf="#+id/Btn6" />
<Button
android:id="#+id/Btn2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/Btn5"
app:layout_constraintEnd_toStartOf="#+id/Btn3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/Btn1"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/Btn1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toTopOf="#+id/Btn4"
app:layout_constraintEnd_toStartOf="#+id/Btn2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ButtonStyle" />
<Button
android:id="#+id/Btn6"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toTopOf="#+id/Btn9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/Btn5"
app:layout_constraintTop_toBottomOf="#+id/Btn3" />
<Button
android:id="#+id/Btn5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toTopOf="#+id/Btn8"
app:layout_constraintEnd_toStartOf="#+id/Btn6"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/Btn4"
app:layout_constraintTop_toBottomOf="#+id/Btn2" />
<Button
android:id="#+id/Btn7"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/Btn8"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Btn4" />
<Button
android:id="#+id/Btn8"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/Btn9"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/Btn7"
app:layout_constraintTop_toBottomOf="#+id/Btn5" />
<Button
android:id="#+id/Btn3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#android:color/background_light"
android:onClick="SelectBtn"
android:textSize="40sp"
app:layout_constraintBottom_toTopOf="#+id/Btn6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/Btn2"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Android layout_rowWeight for API 14 or lower

I'm trying to do something similar to this using as less code.
I did this using GridLayout. But layout_rowWeight requires API level 21 but I want to use API level 14.
How to do it at a lower API level or using another Layout?
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:layout_row="0"
android:layout_rowWeight="3"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:layout_row="1"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="2"
android:layout_rowWeight="1"
android:clickable="false"
android:text="New Button" />
<Button
android:id="#+id/button24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="3"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="3"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="4"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="3"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="4"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="4"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="5"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="2"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="2"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="5"
android:layout_rowWeight="1"
android:text="New Button" />
<Button
android:id="#+id/button34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="5"
android:layout_rowWeight="1"
android:text="New Button" />

Android - EditText positioning within a TableView row and colum

If someone could point out the really obvious setting im missing I would be grateful!
Im working on a screen layout that has rows and 3 columns. All I want to do is put a EditText control into the first row. Below is the code. Unfortunately I dont have the reputation to post a screen shot - sorry.
<RelativeLayout 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">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="75dp">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/textpin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:layout_gravity="top"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="number"
android:textColor="#3399ff"
android:textSize="35sp" />
<Button
android:id="#+id/btnBack"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:gravity="center_vertical|center_horizontal"
android:drawableTop="#drawable/ic_del"
android:textColor="#android:color/background_light"
android:textSize="40sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn1"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:drawableTop="#drawable/ic_1"
android:textColor="#android:color/white"
android:textSize="30sp" />
<Button
android:id="#+id/btn2"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:drawableTop="#drawable/ic_2"
android:textColor="#android:color/white"
android:textSize="30sp" />
<Button
android:id="#+id/btn3"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:drawableTop="#drawable/ic_3"
android:textColor="#android:color/white"
android:textSize="30sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn4"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:drawableTop="#drawable/ic_4"
android:textColor="#android:color/white"
android:textSize="30sp" />
<Button
android:id="#+id/btn5"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:drawableTop="#drawable/ic_5"
android:textColor="#android:color/white"
android:textSize="30sp" />
<Button
android:id="#+id/btn6"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:drawableTop="#drawable/ic_6"
android:textColor="#android:color/white"
android:textSize="30sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn7"
android:layout_width="150dp"
android:layout_height="130dp"
android:drawableTop="#drawable/ic_7"
android:background="#fffafafa"
android:textColor="#android:color/white"
android:textSize="30sp" />
<Button
android:id="#+id/btn8"
android:layout_width="150dp"
android:layout_height="130dp"
android:drawableTop="#drawable/ic_8"
android:background="#fffafafa"
android:textColor="#android:color/white"
android:textSize="30sp" />
<Button
android:id="#+id/btn9"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:gravity="center"
android:drawableTop="#drawable/ic_9"
android:textColor="#android:color/white"
android:textSize="30sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn0"
android:layout_width="150dp"
android:layout_height="130dp"
android:layout_column="1"
android:drawableTop="#drawable/ic_0"
android:background="#fffafafa"
android:textColor="#android:color/white"
android:textSize="30sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/cancelB"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:drawableTop="#drawable/ic_cancel"
android:textColor="#android:color/white"
android:textSize="25sp" />
<Button
android:id="#+id/confermB"
android:layout_width="150dp"
android:layout_height="130dp"
android:background="#fffafafa"
android:layout_column="2"
android:drawableTop="#drawable/ic_ok"
android:textColor="#android:color/white"
android:textSize="25sp" />
</TableRow>
</TableLayout>
Has anyone any ideas?
Thanks
Steve
After much messing around I found this fixed it :-
<EditText
android:id="#+id/textpin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:layout_gravity="center_vertical"
android:cursorVisible="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="number"
android:textColor="#3399ff"
android:textSize="40sp" />

Resources