Skip to content

Commit 6499257

Browse files
Merge pull request #246 from MihaiCristianCondrea/codex/optimize-android-xml-layouts-for-performance-5h8dp4
Normalize layout padding shorthands
2 parents 5975eea + 41272ea commit 6499257

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+332
-336
lines changed

app/src/main/res/layout-sw600dp/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
app:layout_constraintStart_toEndOf="@id/nav_view"
4040
app:layout_constraintTop_toBottomOf="@id/app_bar_layout"
4141
app:navGraph="@navigation/mobile_navigation" />
42-
</androidx.constraintlayout.widget.ConstraintLayout>
42+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/activity_alert_dialog.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface"
2525
android:layout_width="wrap_content"
2626
android:layout_height="wrap_content"
27-
android:layout_margin="24dp"
27+
android:layout_marginEnd="24dp"
28+
android:layout_marginBottom="24dp"
2829
android:contentDescription="@string/tooltip_show_java_code_snippet"
2930
android:text="@string/show_code"
3031
android:tooltipText="@string/tooltip_show_java_code_snippet"

app/src/main/res/layout/activity_android_history.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
android:layout_height="wrap_content"
1212
android:orientation="vertical"
1313
android:paddingHorizontal="24dp"
14-
android:paddingTop="24dp"
15-
android:paddingBottom="24dp">
14+
android:paddingVertical="24dp">
1615

1716
<com.google.android.material.textview.MaterialTextView
1817
android:id="@+id/text_view_history"

app/src/main/res/layout/activity_android_start_project.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
android:layout_height="wrap_content"
3232
android:orientation="vertical"
3333
android:paddingHorizontal="24dp"
34-
android:paddingTop="24dp"
35-
android:paddingBottom="24dp">
34+
android:paddingVertical="24dp">
3635

3736
<com.google.android.material.textview.MaterialTextView
3837
android:id="@+id/text_view_first_step"

app/src/main/res/layout/activity_bottom_navigation.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface"
3030
android:layout_width="wrap_content"
3131
android:layout_height="wrap_content"
32-
android:layout_margin="24dp"
32+
android:layout_marginEnd="24dp"
33+
android:layout_marginBottom="24dp"
3334
android:contentDescription="@string/tooltip_show_java_code_snippet"
3435
android:text="@string/show_code"
3536
android:tooltipText="@string/tooltip_show_java_code_snippet"

app/src/main/res/layout/activity_buttons.xml

Lines changed: 43 additions & 44 deletions
Large diffs are not rendered by default.

app/src/main/res/layout/activity_chronometer.xml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,34 @@
1515

1616
<androidx.appcompat.widget.LinearLayoutCompat
1717
android:layout_width="match_parent"
18-
android:layout_height="match_parent"
19-
android:orientation="vertical">
18+
android:layout_height="wrap_content"
19+
android:orientation="vertical"
20+
android:paddingHorizontal="24dp">
2021

2122
<com.google.android.material.textview.MaterialTextView
2223
style="@style/TextAppearance.Material3.HeadlineLarge"
2324
android:layout_width="wrap_content"
2425
android:layout_height="wrap_content"
25-
android:layout_marginStart="24dp"
2626
android:layout_marginTop="24dp"
2727
android:text="@string/description" />
2828

2929
<com.google.android.material.card.MaterialCardView
3030
android:layout_width="match_parent"
3131
android:layout_height="wrap_content"
32-
android:layout_margin="24dp"
33-
app:cardCornerRadius="24dp">
32+
android:layout_marginVertical="24dp"
33+
app:cardCornerRadius="24dp"
34+
app:contentPadding="24dp">
3435

3536
<com.google.android.material.textview.MaterialTextView
3637
android:layout_width="match_parent"
3738
android:layout_height="wrap_content"
38-
android:layout_margin="24dp"
3939
android:text="@string/summary_chronometer" />
4040
</com.google.android.material.card.MaterialCardView>
4141

4242
<com.google.android.material.textview.MaterialTextView
4343
style="@style/TextAppearance.Material3.HeadlineLarge"
4444
android:layout_width="wrap_content"
4545
android:layout_height="wrap_content"
46-
android:layout_marginStart="24dp"
4746
android:text="@string/layout_preview" />
4847

4948
<Chronometer
@@ -52,7 +51,7 @@
5251
android:layout_width="wrap_content"
5352
android:layout_height="wrap_content"
5453
android:layout_gravity="center"
55-
android:layout_margin="24dp"
54+
android:layout_marginVertical="24dp"
5655
android:text="00:00"
5756
tools:ignore="HardcodedText" />
5857

@@ -61,27 +60,23 @@
6160
style="@style/Widget.Material3.Button.ElevatedButton"
6261
android:layout_width="match_parent"
6362
android:layout_height="wrap_content"
64-
android:layout_marginStart="24dp"
6563
android:layout_marginTop="24dp"
66-
android:layout_marginEnd="24dp"
6764
android:text="@string/start" />
6865

6966
<com.google.android.material.button.MaterialButton
7067
android:id="@+id/button_stop"
7168
style="@style/Widget.Material3.Button.ElevatedButton"
7269
android:layout_width="match_parent"
7370
android:layout_height="wrap_content"
74-
android:layout_marginStart="24dp"
7571
android:layout_marginTop="24dp"
76-
android:layout_marginEnd="24dp"
7772
android:text="@string/stop" />
7873

7974
<com.google.android.material.button.MaterialButton
8075
android:id="@+id/button_reset"
8176
style="@style/Widget.Material3.Button.ElevatedButton"
8277
android:layout_width="match_parent"
8378
android:layout_height="wrap_content"
84-
android:layout_margin="24dp"
79+
android:layout_marginVertical="24dp"
8580
android:text="@string/reset" />
8681
</androidx.appcompat.widget.LinearLayoutCompat>
8782
</me.zhanghai.android.fastscroll.FastScrollScrollView>
@@ -91,7 +86,8 @@
9186
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface"
9287
android:layout_width="wrap_content"
9388
android:layout_height="wrap_content"
94-
android:layout_margin="24dp"
89+
android:layout_marginEnd="24dp"
90+
android:layout_marginBottom="24dp"
9591
android:contentDescription="@string/tooltip_show_java_code_snippet"
9692
android:text="@string/show_code"
9793
android:textSize="14sp"

app/src/main/res/layout/activity_clock.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,79 +16,78 @@
1616
<androidx.appcompat.widget.LinearLayoutCompat
1717
android:layout_width="match_parent"
1818
android:layout_height="wrap_content"
19-
android:orientation="vertical">
19+
android:orientation="vertical"
20+
android:paddingHorizontal="24dp">
2021

2122
<com.google.android.material.textview.MaterialTextView
2223
style="@style/TextAppearance.Material3.HeadlineLarge"
2324
android:layout_width="wrap_content"
2425
android:layout_height="wrap_content"
25-
android:layout_marginStart="24dp"
2626
android:layout_marginTop="24dp"
2727
android:text="@string/description" />
2828

2929
<com.google.android.material.card.MaterialCardView
3030
android:layout_width="match_parent"
3131
android:layout_height="wrap_content"
32-
android:layout_margin="24dp"
33-
app:cardCornerRadius="24dp">
32+
android:layout_marginVertical="24dp"
33+
app:cardCornerRadius="24dp"
34+
app:contentPadding="24dp">
3435

3536
<com.google.android.material.textview.MaterialTextView
3637
android:layout_width="match_parent"
3738
android:layout_height="wrap_content"
38-
android:layout_margin="24dp"
3939
android:text="@string/summary_clocks" />
4040
</com.google.android.material.card.MaterialCardView>
4141

4242
<com.google.android.material.textview.MaterialTextView
4343
style="@style/TextAppearance.Material3.HeadlineLarge"
4444
android:layout_width="wrap_content"
4545
android:layout_height="wrap_content"
46-
android:layout_marginStart="24dp"
4746
android:text="@string/layout_preview" />
4847

4948
<com.google.android.material.textview.MaterialTextView
5049
android:id="@+id/simpleAnalogClockText"
5150
style="@style/TextAppearance.Material3.HeadlineSmall"
5251
android:layout_width="wrap_content"
5352
android:layout_height="wrap_content"
54-
android:layout_margin="24dp"
53+
android:layout_marginVertical="24dp"
5554
android:text="@string/clock_analog" />
5655

5756
<AnalogClock
5857
android:id="@+id/simpleAnalogClock"
5958
android:layout_width="wrap_content"
6059
android:layout_height="108dp"
6160
android:layout_gravity="center"
62-
android:layout_margin="24dp" />
61+
android:layout_marginVertical="24dp" />
6362

6463
<com.google.android.material.textview.MaterialTextView
6564
style="@style/TextAppearance.Material3.HeadlineSmall"
6665
android:layout_width="wrap_content"
6766
android:layout_height="wrap_content"
68-
android:layout_margin="24dp"
67+
android:layout_marginVertical="24dp"
6968
android:text="@string/clock_digital" />
7069

7170
<DigitalClock
7271
android:id="@+id/digital_clock"
7372
android:layout_width="wrap_content"
7473
android:layout_height="wrap_content"
7574
android:layout_gravity="center"
76-
android:layout_margin="24dp" />
75+
android:layout_marginVertical="24dp" />
7776

7877
<com.google.android.material.textview.MaterialTextView
7978
android:id="@+id/simpleTextClockText"
8079
style="@style/TextAppearance.Material3.HeadlineSmall"
8180
android:layout_width="wrap_content"
8281
android:layout_height="wrap_content"
83-
android:layout_margin="24dp"
82+
android:layout_marginVertical="24dp"
8483
android:text="@string/clock_text" />
8584

8685
<TextClock
8786
android:id="@+id/simpleTextClock"
8887
android:layout_width="wrap_content"
8988
android:layout_height="wrap_content"
9089
android:layout_gravity="center"
91-
android:layout_margin="24dp" />
90+
android:layout_marginVertical="24dp" />
9291
</androidx.appcompat.widget.LinearLayoutCompat>
9392
</me.zhanghai.android.fastscroll.FastScrollScrollView>
9493

@@ -97,7 +96,8 @@
9796
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface"
9897
android:layout_width="wrap_content"
9998
android:layout_height="wrap_content"
100-
android:layout_margin="24dp"
99+
android:layout_marginEnd="24dp"
100+
android:layout_marginBottom="24dp"
101101
android:contentDescription="@string/tooltip_show_java_code_snippet"
102102
android:text="@string/show_code"
103103
android:textSize="14sp"

app/src/main/res/layout/activity_date_picker.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/container"
66
android:layout_width="match_parent"
7-
android:layout_height="match_parent">
7+
android:layout_height="match_parent"
8+
android:paddingHorizontal="24dp"
9+
android:paddingTop="24dp">
810

911
<com.google.android.material.textview.MaterialTextView
1012
android:id="@+id/currentDateTextView"
1113
android:layout_width="wrap_content"
1214
android:layout_height="wrap_content"
13-
android:layout_margin="24dp"
15+
android:layout_marginBottom="24dp"
1416
android:drawableStart="@drawable/ic_date_range"
1517
android:text="@string/current_date"
1618
android:textColor="?attr/colorAccent"
@@ -24,7 +26,7 @@
2426
style="@style/Widget.Material3.Button.ElevatedButton"
2527
android:layout_width="wrap_content"
2628
android:layout_height="wrap_content"
27-
android:layout_margin="24dp"
29+
android:layout_marginTop="24dp"
2830
android:text="@string/change_date"
2931
app:layout_constraintBottom_toBottomOf="parent"
3032
app:layout_constraintEnd_toEndOf="parent"
@@ -35,7 +37,7 @@
3537
android:id="@+id/dateTextView"
3638
android:layout_width="wrap_content"
3739
android:layout_height="wrap_content"
38-
android:layout_margin="24dp"
40+
android:layout_marginBottom="24dp"
3941
android:textSize="24sp"
4042
app:layout_constraintBottom_toTopOf="@id/changeDateButton"
4143
app:layout_constraintEnd_toEndOf="parent"
@@ -46,7 +48,7 @@
4648
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface"
4749
android:layout_width="wrap_content"
4850
android:layout_height="wrap_content"
49-
android:layout_margin="24dp"
51+
android:layout_marginBottom="24dp"
5052
android:contentDescription="@string/tooltip_show_java_code_snippet"
5153
android:text="@string/show_code"
5254
android:textSize="14sp"
@@ -55,4 +57,4 @@
5557
app:layout_constraintBottom_toBottomOf="parent"
5658
app:layout_constraintEnd_toEndOf="parent"
5759
tools:targetApi="26" />
58-
</androidx.constraintlayout.widget.ConstraintLayout>
60+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/activity_grid_view.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
android:id="@+id/grid_view"
1111
android:layout_width="match_parent"
1212
android:layout_height="match_parent"
13-
android:layout_marginStart="24dp"
13+
android:layout_marginHorizontal="24dp"
1414
android:layout_marginTop="24dp"
15-
android:layout_marginEnd="24dp"
1615
android:layout_marginBottom="80dp"
1716
android:columnWidth="48dp"
1817
android:numColumns="auto_fit" />
@@ -22,7 +21,8 @@
2221
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface"
2322
android:layout_width="wrap_content"
2423
android:layout_height="wrap_content"
25-
android:layout_margin="24dp"
24+
android:layout_marginEnd="24dp"
25+
android:layout_marginBottom="24dp"
2626
android:contentDescription="@string/tooltip_show_java_code_snippet"
2727
android:text="@string/show_code"
2828
android:textSize="14sp"
@@ -31,4 +31,4 @@
3131
app:layout_constraintBottom_toBottomOf="parent"
3232
app:layout_constraintEnd_toEndOf="parent"
3333
tools:targetApi="26" />
34-
</androidx.constraintlayout.widget.ConstraintLayout>
34+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)