Skip to content

Commit 26c154c

Browse files
committed
refactor(functions): replace RelativeLayout with ConstraintLayout
1 parent 8fb7bcb commit 26c154c

File tree

1 file changed

+95
-87
lines changed

1 file changed

+95
-87
lines changed

functions/app/src/main/res/layout/activity_main.xml

+95-87
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ specific language governing permissions and limitations under the License.
4141
app:cardBackgroundColor="@android:color/white"
4242
app:cardUseCompatPadding="true">
4343

44-
<RelativeLayout
44+
<androidx.constraintlayout.widget.ConstraintLayout
4545
android:layout_width="match_parent"
46-
android:layout_height="match_parent"
46+
android:layout_height="wrap_content"
4747
android:padding="16dp">
4848

4949
<TextView
@@ -52,69 +52,76 @@ specific language governing permissions and limitations under the License.
5252
android:layout_height="wrap_content"
5353
android:text="@string/heading_add_numbers"
5454
android:textSize="20sp"
55-
android:textStyle="bold" />
55+
android:textStyle="bold"
56+
app:layout_constraintStart_toStartOf="parent"
57+
app:layout_constraintTop_toTopOf="parent" />
5658

59+
<EditText
60+
android:id="@+id/fieldFirstNumber"
61+
android:layout_width="50dp"
62+
android:layout_height="wrap_content"
63+
android:gravity="center"
64+
android:inputType="number"
65+
app:layout_constraintStart_toStartOf="@+id/header_add_numbers"
66+
app:layout_constraintTop_toBottomOf="@+id/header_add_numbers"
67+
tools:text="1" />
5768

58-
<LinearLayout
59-
android:id="@+id/form_add_numbers"
60-
android:layout_width="match_parent"
69+
<TextView
70+
android:id="@+id/labelPlus"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:text="@string/plus"
74+
android:textSize="14sp"
75+
android:textStyle="bold"
76+
app:layout_constraintBottom_toBottomOf="@+id/fieldFirstNumber"
77+
app:layout_constraintStart_toEndOf="@+id/fieldFirstNumber"
78+
app:layout_constraintTop_toTopOf="@+id/fieldFirstNumber" />
79+
80+
<EditText
81+
android:id="@+id/fieldSecondNumber"
82+
android:layout_width="50dp"
6183
android:layout_height="wrap_content"
62-
android:layout_below="@+id/header_add_numbers"
63-
android:orientation="horizontal">
64-
65-
<EditText
66-
android:id="@+id/fieldFirstNumber"
67-
android:layout_width="50dp"
68-
android:layout_height="wrap_content"
69-
android:gravity="center"
70-
android:inputType="number"
71-
tools:text="1" />
72-
73-
<TextView
74-
android:layout_width="wrap_content"
75-
android:layout_height="wrap_content"
76-
android:text="@string/plus"
77-
android:textSize="14sp"
78-
android:textStyle="bold" />
79-
80-
<EditText
81-
android:id="@+id/fieldSecondNumber"
82-
android:layout_width="50dp"
83-
android:layout_height="wrap_content"
84-
android:gravity="center"
85-
android:inputType="number"
86-
tools:text="1" />
87-
88-
<TextView
89-
android:layout_width="wrap_content"
90-
android:layout_height="wrap_content"
91-
android:text="@string/equals"
92-
android:textSize="14sp"
93-
android:textStyle="bold" />
94-
95-
<EditText
96-
android:id="@+id/fieldAddResult"
97-
android:layout_width="50dp"
98-
android:layout_height="wrap_content"
99-
android:enabled="false"
100-
android:gravity="center"
101-
android:inputType="number"
102-
tools:text="2" />
103-
104-
</LinearLayout>
84+
android:gravity="center"
85+
android:inputType="number"
86+
tools:text="1"
87+
app:layout_constraintBottom_toBottomOf="@+id/labelPlus"
88+
app:layout_constraintStart_toEndOf="@+id/labelPlus"
89+
app:layout_constraintTop_toTopOf="@+id/labelPlus" />
90+
91+
<TextView
92+
android:id="@+id/labelEquals"
93+
android:layout_width="wrap_content"
94+
android:layout_height="wrap_content"
95+
android:text="@string/equals"
96+
android:textSize="14sp"
97+
android:textStyle="bold"
98+
app:layout_constraintBottom_toBottomOf="@+id/fieldSecondNumber"
99+
app:layout_constraintStart_toEndOf="@+id/fieldSecondNumber"
100+
app:layout_constraintTop_toTopOf="@+id/fieldSecondNumber" />
101+
102+
<EditText
103+
android:id="@+id/fieldAddResult"
104+
android:layout_width="50dp"
105+
android:layout_height="wrap_content"
106+
android:enabled="false"
107+
android:gravity="center"
108+
android:inputType="number"
109+
tools:text="2"
110+
app:layout_constraintBottom_toBottomOf="@+id/labelEquals"
111+
app:layout_constraintStart_toEndOf="@+id/labelEquals"
112+
app:layout_constraintTop_toTopOf="@+id/labelEquals" />
113+
105114

106115
<com.google.android.material.button.MaterialButton
107116
android:id="@+id/buttonCalculate"
108117
style="@style/Widget.MaterialComponents.Button.TextButton"
109118
android:layout_width="wrap_content"
110119
android:layout_height="wrap_content"
111-
android:layout_alignParentEnd="true"
112-
android:layout_alignParentRight="true"
113-
android:layout_below="@+id/form_add_numbers"
114-
android:text="@string/calculate" />
120+
android:text="@string/calculate"
121+
app:layout_constraintEnd_toEndOf="parent"
122+
app:layout_constraintTop_toBottomOf="@+id/fieldFirstNumber" />
115123

116-
117-
</RelativeLayout>
124+
</androidx.constraintlayout.widget.ConstraintLayout>
118125

119126
</com.google.android.material.card.MaterialCardView>
120127

@@ -125,9 +132,9 @@ specific language governing permissions and limitations under the License.
125132
app:cardBackgroundColor="@android:color/white"
126133
app:cardUseCompatPadding="true">
127134

128-
<RelativeLayout
135+
<androidx.constraintlayout.widget.ConstraintLayout
129136
android:layout_width="match_parent"
130-
android:layout_height="match_parent"
137+
android:layout_height="wrap_content"
131138
android:padding="16dp">
132139

133140
<TextView
@@ -136,54 +143,55 @@ specific language governing permissions and limitations under the License.
136143
android:layout_height="wrap_content"
137144
android:text="@string/heading_add_message"
138145
android:textSize="20sp"
139-
android:textStyle="bold" />
140-
146+
android:textStyle="bold"
147+
app:layout_constraintStart_toStartOf="parent"
148+
app:layout_constraintTop_toTopOf="parent" />
141149

142-
<LinearLayout
143-
android:id="@+id/form_add_message"
150+
<EditText
151+
android:id="@+id/fieldMessageInput"
144152
android:layout_width="match_parent"
145153
android:layout_height="wrap_content"
146-
android:layout_below="@+id/header_add_message"
147-
android:orientation="vertical">
148-
149-
<EditText
150-
android:id="@+id/fieldMessageInput"
151-
android:layout_width="match_parent"
152-
android:layout_height="wrap_content"
153-
android:hint="@string/input"
154-
tools:text="some bad message" />
155-
156-
<EditText
157-
android:id="@+id/fieldMessageOutput"
158-
android:layout_width="match_parent"
159-
android:layout_height="wrap_content"
160-
android:enabled="false"
161-
android:hint="@string/output"
162-
tools:text="some clean message" />
163-
164-
</LinearLayout>
154+
android:hint="@string/input"
155+
android:inputType="text"
156+
app:layout_constraintEnd_toEndOf="parent"
157+
app:layout_constraintStart_toStartOf="parent"
158+
app:layout_constraintTop_toBottomOf="@+id/header_add_message"
159+
tools:text="some bad message" />
160+
161+
<EditText
162+
android:id="@+id/fieldMessageOutput"
163+
android:layout_width="match_parent"
164+
android:layout_height="wrap_content"
165+
android:enabled="false"
166+
android:hint="@string/output"
167+
android:inputType="text"
168+
app:layout_constraintEnd_toEndOf="@+id/fieldMessageInput"
169+
app:layout_constraintStart_toStartOf="@+id/fieldMessageInput"
170+
app:layout_constraintTop_toBottomOf="@+id/fieldMessageInput"
171+
tools:text="some clean message" />
165172

166173
<com.google.android.material.button.MaterialButton
167174
android:id="@+id/buttonSignIn"
168175
style="@style/Widget.MaterialComponents.Button.TextButton"
169176
android:layout_width="wrap_content"
170177
android:layout_height="wrap_content"
171178
android:layout_alignTop="@+id/buttonAddMessage"
172-
android:layout_toLeftOf="@+id/buttonAddMessage"
173179
android:layout_toStartOf="@+id/buttonAddMessage"
174-
android:text="@string/sign_in" />
180+
android:layout_toLeftOf="@+id/buttonAddMessage"
181+
android:text="@string/sign_in"
182+
app:layout_constraintEnd_toStartOf="@+id/buttonAddMessage"
183+
app:layout_constraintTop_toBottomOf="@+id/fieldMessageOutput" />
175184

176185
<com.google.android.material.button.MaterialButton
177186
android:id="@+id/buttonAddMessage"
178187
style="@style/Widget.MaterialComponents.Button.TextButton"
179188
android:layout_width="wrap_content"
180189
android:layout_height="wrap_content"
181-
android:layout_alignParentEnd="true"
182-
android:layout_alignParentRight="true"
183-
android:layout_below="@+id/form_add_message"
184-
android:text="@string/add_message" />
190+
android:text="@string/add_message"
191+
app:layout_constraintEnd_toEndOf="@+id/fieldMessageOutput"
192+
app:layout_constraintTop_toBottomOf="@+id/fieldMessageOutput" />
185193

186-
</RelativeLayout>
194+
</androidx.constraintlayout.widget.ConstraintLayout>
187195

188196
</com.google.android.material.card.MaterialCardView>
189197

0 commit comments

Comments
 (0)