Skip to content

Commit d95df1f

Browse files
committed
Fix Fab margin issue on pre-lollipop
1 parent 7801c52 commit d95df1f

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ android {
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
vectorDrawables.useSupportLibrary = true
1314
}
1415
buildTypes {
1516
release {

app/src/main/res/layout-land/country_detail.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<net.huannguyen.conductorexample.countrydetail.CountryDetailView
99
xmlns:android="http://schemas.android.com/apk/res/android"
10+
xmlns:app="http://schemas.android.com/apk/res-auto"
1011
xmlns:tools="http://schemas.android.com/tools"
1112
android:layout_width="match_parent"
1213
android:layout_height="match_parent"
@@ -30,14 +31,15 @@
3031

3132
<android.support.design.widget.FloatingActionButton
3233
android:id="@+id/favourite_fab"
33-
android:layout_width="56dp"
34-
android:layout_height="56dp"
35-
android:src="@drawable/ic_favorite"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
app:srcCompat="@drawable/ic_favorite"
3637
android:scaleType="center"
3738
android:layout_gravity="bottom|end"
38-
android:layout_marginEnd="28dp"
39-
android:layout_marginRight="28dp"
40-
android:layout_marginBottom="-28dp"/>
39+
android:layout_marginEnd="@dimen/fab_margin_right"
40+
android:layout_marginRight="@dimen/fab_margin_right"
41+
android:layout_marginBottom="@dimen/fab_margin_vertical"
42+
app:fabSize="normal"/>
4143
</FrameLayout>
4244

4345
<TableLayout
@@ -57,7 +59,7 @@
5759

5860
<TextView
5961
android:id="@+id/capital"
60-
android:layout_width="0dp"
62+
android:layout_width="wrap_content"
6163
android:layout_height="wrap_content"
6264
style="@style/CountryDataValue"/>
6365
</TableRow>

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<net.huannguyen.conductorexample.countrydetail.CountryDetailView
33
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
@@ -37,7 +38,7 @@
3738

3839
<TextView
3940
android:id="@+id/capital"
40-
android:layout_width="0dp"
41+
android:layout_width="wrap_content"
4142
android:layout_height="wrap_content"
4243
style="@style/CountryDataValue"/>
4344
</TableRow>
@@ -101,13 +102,14 @@
101102

102103
<android.support.design.widget.FloatingActionButton
103104
android:id="@+id/favourite_fab"
104-
android:layout_width="56dp"
105-
android:layout_height="56dp"
105+
android:layout_width="wrap_content"
106+
android:layout_height="wrap_content"
106107
android:layout_gravity="top|end"
107108
android:scaleType="center"
108-
android:src="@drawable/ic_favorite"
109-
android:layout_marginTop="-28dp"
110-
android:layout_marginEnd="28dp"
111-
android:layout_marginRight="28dp"/>
109+
app:srcCompat="@drawable/ic_favorite"
110+
android:layout_marginTop="@dimen/fab_margin_vertical"
111+
android:layout_marginEnd="@dimen/fab_margin_right"
112+
android:layout_marginRight="@dimen/fab_margin_right"
113+
app:fabSize="normal"/>
112114
</FrameLayout>
113115
</net.huannguyen.conductorexample.countrydetail.CountryDetailView>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="fab_margin_vertical">-28dp</dimen>
4+
<dimen name="fab_margin_right">28dp</dimen>
5+
</resources>

app/src/main/res/values/dimens.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<dimen name="touch_raise">8dp</dimen>
3+
<!-- Define different margins for pre and post-lollipop to overcome the problem that FABs
4+
are added an extra margin of 16dp in pre-lollipop -->
5+
<dimen name="fab_margin_vertical">-44dp</dimen>
6+
<dimen name="fab_margin_right">12dp</dimen>
47
</resources>

0 commit comments

Comments
 (0)