1

I want to set BottomSheetBehavior in Xamarin.

This is how it is done, but not in Xamarin:

behavior.isFitToContents = false
behavior.halfExpandedRatio = 0.6f

As can be seen by:

Method setHalfExpandedRatio(float ratio)

In Xamarin, there is FitToContents property, but there is no HalfExpandedRatio property. Is is missing? Can I set halfExpandedRatio in Xamarin?

I need all 3 states: Collapsed, HalfExpanded (with ratio different than 0.5f) and Expaneded

Dela
  • 146
  • 3
  • 15
  • Do you need to achieve it like following code? `var bottomSheetBehavior= BottomSheetBehavior.From(xxxx); bottomSheetBehavior.FitToContents = false; bottomSheetBehavior.PeekHeight = BottomSheetBehavior.StateHalfExpanded;` – Leon Mar 13 '20 at 05:45
  • Yes, but I would like to set the halfExpandedRatio. PeekHeight is not HalfExpandedRatio. PeekHeight is size in pixels and it is used with StateCollapsed. HalfExpandedRatio is a float from 0.0f to 1.0f and it is used with StateHalfExpanded. – Dela Mar 13 '20 at 06:05
  • Xamarin Android have different with native android, You can try it `bottomSheetBehavior.PeekHeight = BottomSheetBehavior.StateHalfExpanded;` replace `setHalfExpandedRatio(float ratio)` in native android – Leon Mar 13 '20 at 06:16
  • Setting `bottomSheetBehavior.PeekHeight = BottomSheetBehavior.StateHalfExpanded` result is a very small bottom sheet in StateCollapsed, 6 pixels height, because that is the value of BottomSheetBehavior.StateHalfExpanded. Ratio is still 0.5f at HalfExpanededState. – Dela Mar 13 '20 at 07:06
  • I cannot find `setHalfExpandedRatio(float ratio)` this method in xamarin android.If ` mBottomSheetBehavior.State = BottomSheetBehavior.StateHalfExpanded;` cannot meet your requirement. You can set the `PeekHeight` dynamically depend on your needs. For example, If you want to set `behavior.halfExpandedRatio = 0.6f`, we can set the value of `PeekHeight` to 0.6 times the height of `bottom_sheet`like following code.`mBottomSheetBehavior.PeekHeight = (int)(bottomSheet.Height*0.6);` – Leon Mar 16 '20 at 08:24
  • Which NuGet package are you using for this? Make sure you are using BottomSheet from https://www.nuget.org/packages/Xamarin.Google.Android.Material/1.1.0-rc2 – Cheesebaron Mar 16 '20 at 15:40
  • @Cheesebaron I am using https://www.nuget.org/packages/Xamarin.Android.Support.Design/28.0.0.3 I did download the one you suggested, but I cannot find BottomSheetBehavior class by now – Dela Mar 17 '20 at 09:07
  • 2
    It is in the namespace `Google.Android.Material.BottomSheet`. However, mixing support packages with AndroidX stuff will be a mess. The features you are looking for are simply not present in the support packages, you need to use the newer AndroidX/Material packages. – Cheesebaron Mar 17 '20 at 09:13

0 Answers0