Skip to content

Commit 0294723

Browse files
committed
feat: ConstraintLayout vs Relative benchmark
1 parent 3a29ef3 commit 0294723

7 files changed

Lines changed: 411 additions & 1 deletion

File tree

906 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2016 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight">
18+
<item>
19+
<shape android:shape="oval">
20+
<solid android:color="?android:colorAccent" />
21+
</shape>
22+
</item>
23+
</ripple>
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
17+
xmlns:app="http://schemas.android.com/apk/res-auto"
18+
android:id="@+id/container"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
22+
<ImageView
23+
android:id="@+id/header"
24+
android:layout_width="0dp"
25+
android:layout_height="150dp"
26+
android:layout_marginBottom="16dp"
27+
android:contentDescription="@string/dummy"
28+
android:scaleType="centerCrop"
29+
android:src="@drawable/singapore"
30+
app:layout_constraintEnd_toEndOf="parent"
31+
app:layout_constraintStart_toStartOf="parent"
32+
app:layout_constraintTop_toTopOf="parent" />
33+
34+
<ImageView
35+
android:id="@+id/favorite"
36+
android:layout_width="36dp"
37+
android:layout_height="36dp"
38+
android:layout_marginEnd="16dp"
39+
android:layout_marginBottom="-16dp"
40+
android:background="@drawable/info_background"
41+
android:contentDescription="@string/dummy"
42+
android:padding="5dp"
43+
android:src="@drawable/ic_star"
44+
app:layout_constraintBottom_toBottomOf="@id/header"
45+
app:layout_constraintEnd_toEndOf="parent" />
46+
47+
<TextView
48+
android:id="@+id/title"
49+
android:layout_width="wrap_content"
50+
android:layout_height="wrap_content"
51+
android:layout_marginStart="16dp"
52+
android:layout_marginTop="16dp"
53+
android:text="@string/singapore"
54+
android:textSize="24sp"
55+
app:layout_constraintStart_toStartOf="parent"
56+
app:layout_constraintTop_toBottomOf="@+id/header" />
57+
58+
<EditText
59+
android:id="@+id/cameraType"
60+
android:layout_width="0dp"
61+
android:layout_height="wrap_content"
62+
android:layout_marginTop="8dp"
63+
android:ems="10"
64+
android:inputType="textPersonName"
65+
android:text="@string/camera_value"
66+
app:layout_constraintEnd_toEndOf="@+id/settings"
67+
app:layout_constraintStart_toStartOf="@+id/settings"
68+
app:layout_constraintTop_toBottomOf="@+id/title" />
69+
70+
<TextView
71+
android:id="@+id/cameraLabel"
72+
android:layout_width="wrap_content"
73+
android:layout_height="wrap_content"
74+
android:layout_marginStart="16dp"
75+
android:labelFor="@+id/cameraType"
76+
android:text="@string/camera"
77+
app:layout_constraintBaseline_toBaselineOf="@+id/cameraType"
78+
app:layout_constraintStart_toStartOf="parent" />
79+
80+
<TextView
81+
android:id="@+id/settingsLabel"
82+
android:layout_width="wrap_content"
83+
android:layout_height="wrap_content"
84+
android:layout_marginStart="16dp"
85+
android:labelFor="@+id/settings"
86+
android:text="@string/settings"
87+
app:layout_constraintBaseline_toBaselineOf="@+id/settings"
88+
app:layout_constraintStart_toStartOf="parent" />
89+
90+
<EditText
91+
android:id="@+id/settings"
92+
android:layout_width="0dp"
93+
android:layout_height="wrap_content"
94+
android:layout_marginStart="6dp"
95+
android:layout_marginTop="8dp"
96+
android:ems="10"
97+
android:inputType="textPersonName"
98+
android:text="@string/camera_settings"
99+
app:layout_constraintEnd_toEndOf="@+id/description"
100+
app:layout_constraintStart_toEndOf="@+id/settingsLabel"
101+
app:layout_constraintTop_toBottomOf="@+id/cameraType" />
102+
103+
<Button
104+
android:id="@+id/upload"
105+
android:layout_width="wrap_content"
106+
android:layout_height="wrap_content"
107+
android:layout_marginEnd="16dp"
108+
android:layout_marginBottom="16dp"
109+
android:text="@string/upload"
110+
app:layout_constraintBottom_toBottomOf="parent"
111+
app:layout_constraintEnd_toStartOf="@id/discard" />
112+
113+
<Button
114+
android:id="@+id/discard"
115+
android:layout_width="wrap_content"
116+
android:layout_height="wrap_content"
117+
android:layout_marginEnd="8dp"
118+
android:elevation="0dp"
119+
android:text="@string/discard"
120+
app:layout_constraintBaseline_toBaselineOf="@+id/upload"
121+
app:layout_constraintEnd_toEndOf="parent" />
122+
123+
<TextView
124+
android:id="@+id/description"
125+
android:layout_width="0dp"
126+
android:layout_height="0dp"
127+
android:layout_marginStart="16dp"
128+
android:layout_marginTop="8dp"
129+
android:layout_marginEnd="16dp"
130+
android:layout_marginBottom="8dp"
131+
android:ellipsize="end"
132+
android:fadingEdge="vertical"
133+
android:text="@string/singapore_description"
134+
android:textSize="15sp"
135+
app:layout_constraintBottom_toTopOf="@+id/discard"
136+
app:layout_constraintHeight="wrap_content"
137+
app:layout_constraintLeft_toLeftOf="parent"
138+
app:layout_constraintRight_toRightOf="parent"
139+
app:layout_constraintTop_toBottomOf="@+id/settings"
140+
app:layout_constraintVertical_bias="0" />
141+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:id="@+id/container"
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent">
20+
21+
<ImageView
22+
android:id="@+id/imageview_singapore"
23+
android:layout_width="match_parent"
24+
android:layout_height="150dp"
25+
android:contentDescription="@string/dummy"
26+
android:scaleType="centerCrop"
27+
android:src="@drawable/singapore" />
28+
29+
<ImageView
30+
android:id="@+id/favorite"
31+
android:layout_width="36dp"
32+
android:layout_height="36dp"
33+
android:layout_below="@id/imageview_singapore"
34+
android:layout_alignParentEnd="true"
35+
android:layout_marginTop="-16dp"
36+
android:layout_marginEnd="16dp"
37+
android:background="@drawable/info_background"
38+
android:contentDescription="@string/dummy"
39+
android:padding="5dp"
40+
android:src="@drawable/ic_star" />
41+
42+
<RelativeLayout
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:layout_below="@id/imageview_singapore">
46+
47+
<TextView
48+
android:id="@+id/title"
49+
android:layout_width="wrap_content"
50+
android:layout_height="wrap_content"
51+
android:layout_marginStart="16dp"
52+
android:layout_marginTop="16dp"
53+
android:text="@string/singapore"
54+
android:textSize="24sp" />
55+
56+
<LinearLayout
57+
android:id="@+id/camera_area"
58+
android:layout_width="match_parent"
59+
android:layout_height="wrap_content"
60+
android:layout_below="@id/title"
61+
android:orientation="horizontal">
62+
63+
<TextView
64+
android:id="@+id/cameraLabel"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
android:layout_gravity="center_vertical"
68+
android:layout_marginStart="16dp"
69+
android:labelFor="@+id/cameraType"
70+
android:text="@string/camera" />
71+
72+
<RelativeLayout
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content">
75+
76+
<EditText
77+
android:id="@+id/cameraType"
78+
android:layout_width="match_parent"
79+
android:layout_height="wrap_content"
80+
android:layout_centerVertical="true"
81+
android:layout_marginStart="8dp"
82+
android:layout_marginTop="8dp"
83+
android:layout_marginEnd="8dp"
84+
android:ems="10"
85+
android:inputType="textPersonName"
86+
android:text="@string/camera_value" />
87+
</RelativeLayout>
88+
</LinearLayout>
89+
90+
<LinearLayout
91+
android:id="@+id/setings_area"
92+
android:layout_width="match_parent"
93+
android:layout_height="wrap_content"
94+
android:layout_below="@id/camera_area"
95+
android:orientation="horizontal">
96+
97+
<TextView
98+
android:id="@+id/settingsLabel"
99+
android:layout_width="wrap_content"
100+
android:layout_height="wrap_content"
101+
android:layout_gravity="center_vertical"
102+
android:layout_marginStart="16dp"
103+
android:labelFor="@+id/settings"
104+
android:text="@string/settings" />
105+
106+
<RelativeLayout
107+
android:layout_width="match_parent"
108+
android:layout_height="wrap_content">
109+
110+
<EditText
111+
android:id="@+id/settings"
112+
android:layout_width="match_parent"
113+
android:layout_height="wrap_content"
114+
android:layout_centerVertical="true"
115+
android:layout_marginStart="8dp"
116+
android:layout_marginTop="8dp"
117+
android:layout_marginEnd="8dp"
118+
android:ems="10"
119+
android:inputType="textPersonName"
120+
android:text="@string/camera_settings" />
121+
</RelativeLayout>
122+
</LinearLayout>
123+
124+
<TextView
125+
android:id="@+id/description"
126+
android:layout_width="match_parent"
127+
android:layout_height="wrap_content"
128+
android:layout_below="@id/setings_area"
129+
android:layout_marginStart="16dp"
130+
android:layout_marginTop="8dp"
131+
android:layout_marginEnd="16dp"
132+
android:layout_marginBottom="8dp"
133+
android:ellipsize="end"
134+
android:fadingEdge="vertical"
135+
android:text="@string/singapore_description"
136+
android:textSize="15sp" />
137+
</RelativeLayout>
138+
139+
<LinearLayout
140+
android:layout_width="wrap_content"
141+
android:layout_height="wrap_content"
142+
android:layout_alignParentEnd="true"
143+
android:layout_alignParentBottom="true">
144+
145+
<Button
146+
android:id="@+id/upload"
147+
android:layout_width="wrap_content"
148+
android:layout_height="wrap_content"
149+
android:layout_marginEnd="16dp"
150+
android:layout_marginBottom="16dp"
151+
android:text="@string/upload" />
152+
153+
<Button
154+
android:id="@+id/discard"
155+
android:layout_width="wrap_content"
156+
android:layout_height="wrap_content"
157+
android:layout_marginEnd="8dp"
158+
android:elevation="0dp"
159+
android:text="@string/discard" />
160+
</LinearLayout>
161+
</RelativeLayout>
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<resources>
2-
<string name="app_name">ui</string>
2+
<string name="app_name">Performance Test App</string>
3+
4+
<string name="singapore_description">Singapore officially the Republic of Singapore, and often referred to as the Lion City, the Garden City, and the Red Dot, is a global city in Southeast Asia and the world\'s only island city-state. It lies one degree (137 km) north of the equator, at the southernmost tip of continental Asia and peninsular Malaysia, with Indonesia\'s Riau Islands to the south. Singapore\'s territory consists of the diamond-shaped main island and 62 islets.</string>
5+
<string name="dummy">dummy</string>
6+
<string name="discard">Discard</string>
7+
<string name="upload">Upload</string>
8+
<string name="camera_settings">ƒ/4 16s ISO 200</string>
9+
<string name="settings">Settings</string>
10+
<string name="camera">Camera</string>
11+
<string name="camera_value">Leica M Typ 240</string>
12+
<string name="singapore">Singapore</string>
13+
314
<string name="mark">Mark</string>
415
<string name="benchmarking_is_awesome">Benchmarking is awesome</string>
516
</resources>

MicrobenchmarkSample/microbenchmark/src/androidTest/java/com/example/benchmark/ViewInflateBenchmark.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ViewInflateBenchmark {
4141
val root = FrameLayout(context)
4242

4343
benchmarkRule.measureRepeated {
44+
@Suppress("UNUSED_VARIABLE")
4445
val inflated = inflater.inflate(R.layout.item_card, root, false)
4546
}
4647
}

0 commit comments

Comments
 (0)