gpt4 book ai didi

android - 谷歌资料库更新后, Bottom Sheet View 无法完全展开吗?

转载 作者:行者123 更新时间:2023-12-03 10:12:20 25 4
gpt4 key购买 nike

早些时候,我使用了 alpha 03 库,该库能够在启动应用程序时扩展 Bottom Sheet View 。

implementation 'com.google.android.material:material:1.1.0-alpha03'



在更新 alpha 04 之后。我发现了我之前使用的代码
无法正常工作,只能看到部分 View 。

implementation 'com.google.android.material:material:1.1.0-alpha04'



但是在向上和向下滑动后, View 可以完美扩展。

首次启动时如何确保 Bottom Sheet 完全可见。先前的代码不正确吗?

这是MainActivity中的代码
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheetSummaryLayout);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
mBottomSheetBehavior.setHideable(false);

Bottom Sheet View 的xml代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools"
android:id="@+id/bottom_sheet_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="100dp"
app:layout_behavior="@string/bottom_sheet_behavior"
tool:behavior_peekHeight="300dp">

<androidx.viewpager.widget.ViewPager
android:id="@+id/pager_summary"
android:layout_width="match_parent"
android:layout_height="321dp"
android:layout_gravity="bottom"
android:background="@drawable/bg_transparent_gradient"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingStart="@dimen/summary_card_left_padding"
android:paddingLeft="@dimen/summary_card_left_padding"
android:paddingEnd="@dimen/summary_card_right_padding"
android:paddingRight="@dimen/summary_card_right_padding" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_summary_bar"
android:layout_gravity="bottom"
android:background="@color/colorPrimaryDark"
app:tabBackground="@drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp" />

</LinearLayout>

最佳答案

尝试下面的代码,我已经在我的一个项目中使用过,您可能会获得帮助

  public class PopUpFragment extends BottomSheetDialogFragment {

@NonNull @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
BottomSheetDialog d = (BottomSheetDialog) dialog;

bottomSheet = (FrameLayout) d.findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View view, int i) {

switch (i){

case BottomSheetBehavior.STATE_HIDDEN:
dialog.dismiss();

break;
default:
break;
}
}

@Override
public void onSlide(@NonNull View view, float v) {
setScrim(v);

}
});
}
});

// Do something with your dialog like setContentView() or whatever
return dialog;
}
private void setScrim(float slideOffset) {
// bottomSheet.getForeground().setAlpha((int) (slideOffset * 150));


}

public static PopUpFragment newInstance() {

PopUpFragment fragment = new PopUpFragment();

return fragment;
}


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.your_layou, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);


}

}

显示BottomSheet
  PopUpFragment bottomDialogFragment =
PopUpFragment.newInstance();

bottomDialogFragment.show(getChildFragmentManager(),"PopUpFragment");

关于android - 谷歌资料库更新后, Bottom Sheet View 无法完全展开吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55175696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com