mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Add halfExpandedOffset to BottomSheet catalog demo
GIT_ORIGIN_REV_ID=da446b5182eaf192d75c81b552f30e95373c5598 PiperOrigin-RevId: 243127218
This commit is contained in:
parent
b7e252cea4
commit
d0724dd590
@ -34,6 +34,7 @@ import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import io.material.catalog.feature.DemoFragment;
|
||||
@ -75,13 +76,21 @@ public class BottomSheetMainDemoFragment extends DemoFragment {
|
||||
|
||||
View bottomSheetChildView = view.findViewById(R.id.bottom_drawer);
|
||||
ViewGroup.LayoutParams params = bottomSheetChildView.getLayoutParams();
|
||||
BottomSheetBehavior<View> bottomSheetBehavior =
|
||||
BottomSheetBehavior.from(bottomSheetChildView);
|
||||
View modalBottomSheetChildView = bottomSheetDialog.findViewById(R.id.bottom_drawer_2);
|
||||
ViewGroup.LayoutParams layoutParams = modalBottomSheetChildView.getLayoutParams();
|
||||
BottomSheetBehavior<FrameLayout> modalBottomSheetBehavior =
|
||||
bottomSheetDialog.getBehavior();
|
||||
boolean fitToContents = true;
|
||||
float halfExpandedRatio = 0.5f;
|
||||
|
||||
if (params != null && layoutParams != null) {
|
||||
if (isChecked) {
|
||||
params.height = windowHeight;
|
||||
layoutParams.height = windowHeight;
|
||||
fitToContents = false;
|
||||
halfExpandedRatio = 0.7f;
|
||||
|
||||
} else {
|
||||
params.height = (windowHeight * 3 / 5);
|
||||
@ -89,6 +98,10 @@ public class BottomSheetMainDemoFragment extends DemoFragment {
|
||||
}
|
||||
bottomSheetChildView.setLayoutParams(params);
|
||||
modalBottomSheetChildView.setLayoutParams(layoutParams);
|
||||
bottomSheetBehavior.setFitToContents(fitToContents);
|
||||
modalBottomSheetBehavior.setFitToContents(fitToContents);
|
||||
bottomSheetBehavior.setHalfExpandedRatio(halfExpandedRatio);
|
||||
modalBottomSheetBehavior.setHalfExpandedRatio(halfExpandedRatio);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -126,6 +139,14 @@ public class BottomSheetMainDemoFragment extends DemoFragment {
|
||||
case BottomSheetBehavior.STATE_COLLAPSED:
|
||||
text.setText(R.string.cat_bottomsheet_state_collapsed);
|
||||
break;
|
||||
case BottomSheetBehavior.STATE_HALF_EXPANDED:
|
||||
BottomSheetBehavior<View> bottomSheetBehavior =
|
||||
BottomSheetBehavior.from(bottomSheet);
|
||||
text.setText(
|
||||
getString(
|
||||
R.string.cat_bottomsheet_state_half_expanded,
|
||||
bottomSheetBehavior.getHalfExpandedRatio()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -34,6 +34,9 @@
|
||||
<string name="cat_bottomsheet_state_expanded" translatable="false">
|
||||
STATE_EXPANDED
|
||||
</string>
|
||||
<string name="cat_bottomsheet_state_half_expanded" translatable="false">
|
||||
STATE_HALF_EXPANDED\nhalfExpandedRatio = %.2f
|
||||
</string>
|
||||
<string name="cat_bottomsheet_persistent">
|
||||
Persistent Bottomsheet
|
||||
</string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user