Skip to content

Commit 46ffd96

Browse files
authored
Remove RelativeLayout from Database quickstart (#1244)
1 parent ccab3e1 commit 46ffd96

File tree

10 files changed

+220
-201
lines changed

10 files changed

+220
-201
lines changed

database/app/src/androidTest/java/com/google/firebase/quickstart/database/NewPostTest.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,22 @@ public void newPostTest() {
4848

4949
// Select email field
5050
ViewInteraction appCompatEditText = onView(
51-
allOf(withId(R.id.fieldEmail),
52-
withParent(withId(R.id.layoutEmailPassword)),
53-
isDisplayed()));
51+
allOf(withId(R.id.fieldEmail), isDisplayed()));
5452
appCompatEditText.perform(click());
5553

5654
// Enter email address
5755
ViewInteraction appCompatEditText2 = onView(
58-
allOf(withId(R.id.fieldEmail),
59-
withParent(withId(R.id.layoutEmailPassword)),
60-
isDisplayed()));
56+
allOf(withId(R.id.fieldEmail), isDisplayed()));
6157
appCompatEditText2.perform(replaceText(email));
6258

6359
// Enter password
6460
ViewInteraction appCompatEditText3 = onView(
65-
allOf(withId(R.id.fieldPassword),
66-
withParent(withId(R.id.layoutEmailPassword)),
67-
isDisplayed()));
61+
allOf(withId(R.id.fieldPassword), isDisplayed()));
6862
appCompatEditText3.perform(replaceText(password));
6963

7064
// Click sign up
7165
ViewInteraction appCompatButton = onView(
72-
allOf(withId(R.id.buttonSignUp), withText(R.string.sign_up),
73-
withParent(withId(R.id.layoutButtons)),
74-
isDisplayed()));
66+
allOf(withId(R.id.buttonSignUp), withText(R.string.sign_up), isDisplayed()));
7567
appCompatButton.perform(click());
7668

7769
// Click new post button
@@ -111,9 +103,7 @@ public void newPostTest() {
111103

112104
// Check that it has zero stars
113105
ViewInteraction textView3 = onView(
114-
allOf(withId(R.id.postNumStars), withText("0"),
115-
withParent(withId(R.id.starLayout)),
116-
isDisplayed()));
106+
allOf(withId(R.id.postNumStars), withText("0"), isDisplayed()));
117107
textView3.check(matches(withText("0")));
118108

119109
}
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
xmlns:tools="http://schemas.android.com/tools"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent">
67

78
<com.google.android.material.tabs.TabLayout
89
android:id="@+id/tabs"
910
android:layout_width="match_parent"
10-
android:layout_height="wrap_content" />
11+
android:layout_height="wrap_content"
12+
app:layout_constraintTop_toTopOf="parent"
13+
/>
1114

1215
<androidx.viewpager.widget.ViewPager
1316
android:id="@+id/container"
1417
android:layout_width="match_parent"
15-
android:layout_height="match_parent"
16-
android:layout_below="@+id/tabs" />
18+
android:layout_height="0dp"
19+
app:layout_constraintBottom_toBottomOf="parent"
20+
app:layout_constraintTop_toBottomOf="@+id/tabs" />
1721

1822
<com.google.android.material.floatingactionbutton.FloatingActionButton
1923
android:id="@+id/fabNewPost"
2024
android:layout_width="wrap_content"
2125
android:layout_height="wrap_content"
22-
android:layout_alignParentBottom="true"
23-
android:layout_alignParentRight="true"
26+
android:layout_marginEnd="16dp"
27+
android:layout_marginRight="16dp"
28+
android:layout_marginBottom="16dp"
2429
android:src="@drawable/ic_image_edit"
25-
android:layout_margin="16dp"/>
30+
app:layout_constraintBottom_toBottomOf="parent"
31+
app:layout_constraintEnd_toEndOf="parent"
32+
/>
2633

27-
</RelativeLayout>
34+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
35
xmlns:tools="http://schemas.android.com/tools"
46
android:layout_width="match_parent"
57
android:layout_height="match_parent">
@@ -8,34 +10,45 @@
810
android:id="@+id/fieldTitle"
911
android:layout_width="match_parent"
1012
android:layout_height="wrap_content"
11-
android:layout_marginBottom="5dp"
13+
android:layout_marginStart="16dp"
1214
android:layout_marginLeft="16dp"
13-
android:layout_marginRight="16dp"
1415
android:layout_marginTop="16dp"
16+
android:layout_marginEnd="16dp"
17+
android:layout_marginRight="16dp"
1518
android:hint="Title"
16-
android:maxLines="1" />
19+
android:maxLines="1"
20+
app:layout_constraintEnd_toEndOf="parent"
21+
app:layout_constraintStart_toStartOf="parent"
22+
app:layout_constraintTop_toTopOf="parent"
23+
/>
1724

1825
<EditText
1926
android:id="@+id/fieldBody"
2027
android:layout_width="match_parent"
2128
android:layout_height="wrap_content"
22-
android:layout_below="@+id/fieldTitle"
23-
android:layout_marginBottom="5dp"
29+
android:layout_marginStart="16dp"
2430
android:layout_marginLeft="16dp"
31+
android:layout_marginTop="8dp"
32+
android:layout_marginEnd="16dp"
2533
android:layout_marginRight="16dp"
26-
android:layout_marginTop="5dp"
2734
android:hint="Write your post..."
2835
android:inputType="textMultiLine"
2936
android:maxLines="10"
30-
android:scrollHorizontally="false" />
37+
android:scrollHorizontally="false"
38+
app:layout_constraintEnd_toEndOf="parent"
39+
app:layout_constraintStart_toStartOf="parent"
40+
app:layout_constraintTop_toBottomOf="@+id/fieldTitle"
41+
/>
3142

3243
<com.google.android.material.floatingactionbutton.FloatingActionButton
3344
android:id="@+id/fabSubmitPost"
3445
android:layout_width="wrap_content"
3546
android:layout_height="wrap_content"
36-
android:layout_alignParentBottom="true"
37-
android:layout_alignParentRight="true"
38-
android:layout_margin="16dp"
39-
android:src="@drawable/ic_navigation_check_24"/>
47+
android:layout_marginEnd="16dp"
48+
android:layout_marginRight="16dp"
49+
android:layout_marginBottom="16dp"
50+
android:src="@drawable/ic_navigation_check_24"
51+
app:layout_constraintBottom_toBottomOf="parent"
52+
app:layout_constraintEnd_toEndOf="parent" />
4053

41-
</RelativeLayout>
54+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,66 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
xmlns:tools="http://schemas.android.com/tools"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
6-
android:paddingBottom="@dimen/activity_vertical_margin"
77
android:paddingLeft="@dimen/activity_horizontal_margin"
8+
android:paddingTop="@dimen/activity_vertical_margin"
89
android:paddingRight="@dimen/activity_horizontal_margin"
9-
android:paddingTop="@dimen/activity_vertical_margin">
10+
android:paddingBottom="@dimen/activity_vertical_margin">
1011

1112
<include
1213
android:id="@+id/postAuthorLayout"
1314
layout="@layout/include_post_author"
1415
android:layout_width="wrap_content"
1516
android:layout_height="wrap_content"
16-
android:layout_alignParentLeft="true" />
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintTop_toTopOf="parent" />
1719

1820
<include
1921
android:id="@+id/postTextLayout"
2022
layout="@layout/include_post_text"
2123
android:layout_width="wrap_content"
2224
android:layout_height="wrap_content"
23-
android:layout_alignParentLeft="true"
24-
android:layout_below="@+id/postAuthorLayout"
25-
android:layout_marginLeft="5dp"
26-
android:layout_marginTop="10dp" />
25+
android:layout_marginStart="8dp"
26+
android:layout_marginLeft="8dp"
27+
android:layout_marginTop="8dp"
28+
app:layout_constraintStart_toStartOf="parent"
29+
app:layout_constraintTop_toBottomOf="@+id/postAuthorLayout" />
2730

28-
<LinearLayout
29-
android:id="@+id/commentForm"
30-
android:layout_width="match_parent"
31+
<EditText
32+
android:id="@+id/fieldCommentText"
33+
android:layout_width="0dp"
3134
android:layout_height="wrap_content"
32-
android:orientation="horizontal"
33-
android:layout_below="@+id/postTextLayout"
34-
android:layout_marginTop="20dp"
35-
android:weightSum="1.0">
35+
android:layout_marginTop="16dp"
36+
android:hint="Write a comment..."
37+
android:maxLines="1"
38+
app:layout_constraintEnd_toStartOf="@+id/buttonPostComment"
39+
app:layout_constraintHorizontal_bias="0.5"
40+
app:layout_constraintHorizontal_weight="8"
41+
app:layout_constraintStart_toStartOf="parent"
42+
app:layout_constraintTop_toBottomOf="@+id/postTextLayout" />
3643

37-
<EditText
38-
android:id="@+id/fieldCommentText"
39-
android:layout_width="0dp"
40-
android:layout_weight="0.8"
41-
android:layout_height="wrap_content"
42-
android:maxLines="1"
43-
android:hint="Write a comment..."/>
44-
45-
<com.google.android.material.button.MaterialButton
46-
android:id="@+id/buttonPostComment"
47-
style="@style/Widget.MaterialComponents.Button.TextButton"
48-
android:layout_width="0dp"
49-
android:layout_weight="0.2"
50-
android:layout_height="wrap_content"
51-
android:text="Post"/>
52-
53-
</LinearLayout>
44+
<com.google.android.material.button.MaterialButton
45+
android:id="@+id/buttonPostComment"
46+
style="@style/Widget.MaterialComponents.Button.TextButton"
47+
android:layout_width="0dp"
48+
android:layout_height="wrap_content"
49+
android:text="Post"
50+
app:layout_constraintEnd_toEndOf="parent"
51+
app:layout_constraintHorizontal_bias="0.5"
52+
app:layout_constraintHorizontal_weight="2"
53+
app:layout_constraintStart_toEndOf="@+id/fieldCommentText"
54+
app:layout_constraintTop_toTopOf="@+id/fieldCommentText" />
5455

5556
<androidx.recyclerview.widget.RecyclerView
5657
android:id="@+id/recyclerPostComments"
57-
android:layout_width="match_parent"
58-
android:layout_height="match_parent"
59-
android:layout_below="@+id/commentForm"
58+
android:layout_width="0dp"
59+
android:layout_height="0dp"
60+
app:layout_constraintBottom_toBottomOf="parent"
61+
app:layout_constraintEnd_toEndOf="parent"
62+
app:layout_constraintStart_toStartOf="parent"
63+
app:layout_constraintTop_toBottomOf="@+id/buttonPostComment"
6064
tools:listitem="@layout/item_comment" />
6165

62-
</RelativeLayout>
66+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)