Android Prevent Box From Resizing
I am trying to make a four function calculator app. The two blank lines are the numbers involved in the calculations. The issue I have is with the 'result' box. Since I used relati
Solution 1:
So you may not use Relative Layout. But can we use TableLayout?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_weight="2"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<EditText
android:inputType="number"
android:layout_gravity="bottom"
android:id="@+id/num_1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Space android:layout_weight="1"
android:layout_width="0dp"/>
<EditText
android:inputType="number"
android:layout_gravity="bottom"
android:id="@+id/num_2"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<TextView
android:singleLine="true"
android:text="Result"
android:gravity="center"
android:textSize="24sp"
android:id="@+id/result"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_column="18" />
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<Button
android:text="ADD"
android:id="@+id/add"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"/>
<Space
android:layout_width="0dp"
android:layout_weight="2"
/>
<Button
android:text="SUBTRACT"
android:id="@+id/sub"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_margin="20dp"
android:layout_height="0dp"
android:layout_width="match_parent">
<Button
android:text="MULTIPLY"
android:id="@+id/multi"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"/>
<Space
android:layout_width="0dp"
android:layout_weight="2"
/>
<Button
android:text="DIVIDE"
android:id="@+id/divide"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
Post a Comment for "Android Prevent Box From Resizing"