From b2419cccbe5476c03ad05ed7340f6dc320b6260e Mon Sep 17 00:00:00 2001 From: Rafael Chagas Date: Thu, 28 Feb 2019 19:17:55 -0300 Subject: [PATCH] Set the main AppBarLayout size as a percentage of its container Signed-off-by: Rafael Chagas --- .../pingplacepicker/ui/PlacePickerActivity.kt | 13 ++++++++++--- .../src/main/res/layout/activity_place_picker.xml | 4 ++-- library/src/main/res/layout/item_place.xml | 4 ++-- library/src/main/res/values-w600dp/dimens.xml | 6 ------ library/src/main/res/values/dimens.xml | 1 - 5 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 library/src/main/res/values-w600dp/dimens.xml diff --git a/library/src/main/java/com/rtchagas/pingplacepicker/ui/PlacePickerActivity.kt b/library/src/main/java/com/rtchagas/pingplacepicker/ui/PlacePickerActivity.kt index 8e0f230..6e9d4fc 100644 --- a/library/src/main/java/com/rtchagas/pingplacepicker/ui/PlacePickerActivity.kt +++ b/library/src/main/java/com/rtchagas/pingplacepicker/ui/PlacePickerActivity.kt @@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.drawable.DrawableCompat +import androidx.core.view.doOnLayout import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import androidx.recyclerview.widget.LinearLayoutManager @@ -345,16 +346,22 @@ class PlacePickerActivity : AppCompatActivity(), OnMapReadyCallback, // Disable vertical scrolling on appBarLayout (it messes with the map...) // Set default behavior - val params = appBarLayout.layoutParams as CoordinatorLayout.LayoutParams - params.behavior = AppBarLayout.Behavior() + val appBarLayoutParams = appBarLayout.layoutParams as CoordinatorLayout.LayoutParams + appBarLayoutParams.behavior = AppBarLayout.Behavior() // Disable the drag - val behavior = params.behavior as AppBarLayout.Behavior + val behavior = appBarLayoutParams.behavior as AppBarLayout.Behavior behavior.setDragCallback(object : AppBarLayout.Behavior.DragCallback() { override fun canDrag(appBarLayout: AppBarLayout): Boolean { return false } }) + + // Set the size of AppBarLayout to 68% of the total height + coordinator.doOnLayout { + val size : Int = (it.height * 68) / 100 + appBarLayoutParams.height = size + } } private fun initMap() { diff --git a/library/src/main/res/layout/activity_place_picker.xml b/library/src/main/res/layout/activity_place_picker.xml index cc511a1..e56f916 100644 --- a/library/src/main/res/layout/activity_place_picker.xml +++ b/library/src/main/res/layout/activity_place_picker.xml @@ -2,7 +2,7 @@ @@ -17,7 +17,7 @@ diff --git a/library/src/main/res/layout/item_place.xml b/library/src/main/res/layout/item_place.xml index 2b88914..8e7fdf5 100644 --- a/library/src/main/res/layout/item_place.xml +++ b/library/src/main/res/layout/item_place.xml @@ -48,7 +48,7 @@ android:id="@+id/tvPlaceName" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginTop="16dp" + android:layout_marginTop="@dimen/default_margin" android:ellipsize="end" android:maxLines="1" android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" @@ -61,7 +61,7 @@ android:id="@+id/tvPlaceAddress" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginBottom="16dp" + android:layout_marginBottom="@dimen/default_margin" android:ellipsize="end" android:maxLines="1" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" diff --git a/library/src/main/res/values-w600dp/dimens.xml b/library/src/main/res/values-w600dp/dimens.xml deleted file mode 100644 index ba4cb96..0000000 --- a/library/src/main/res/values-w600dp/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - 300dp - - \ No newline at end of file diff --git a/library/src/main/res/values/dimens.xml b/library/src/main/res/values/dimens.xml index 5a80f07..66742c0 100644 --- a/library/src/main/res/values/dimens.xml +++ b/library/src/main/res/values/dimens.xml @@ -2,7 +2,6 @@ 24dp 32dp - 580dp 48dp 140dp