Skip to content

Commit

Permalink
Set the main AppBarLayout size as a percentage of its container
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Chagas <[email protected]>
  • Loading branch information
rtchagas committed Feb 28, 2019
1 parent 87243ac commit b2419cc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/res/layout/activity_place_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
Expand All @@ -17,7 +17,7 @@
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/tall_toolbar_height"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/res/layout/item_place.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions library/src/main/res/values-w600dp/dimens.xml

This file was deleted.

1 change: 0 additions & 1 deletion library/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<dimen name="icon_size_small">24dp</dimen>
<dimen name="icon_size_medium">32dp</dimen>
<dimen name="tall_toolbar_height">580dp</dimen>
<dimen name="button_my_location_size">48dp</dimen>
<dimen name="place_confirm_images_height">140dp</dimen>

Expand Down

0 comments on commit b2419cc

Please sign in to comment.