Android 活动开始时显示底部工作表

Android 活动开始时显示底部工作表,android,android-studio,bottom-sheet,Android,Android Studio,Bottom Sheet,当活动开始时,我试图在250dp的特定高度保持我的底页可见,并在单击按钮时全屏显示。不幸的是,活动开始时,我的底页不可见。 我使用的是一个持久的底部表单,而不是一个片段,因为我希望仍然使用窗口的其他部分。我该怎么办呢 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layou

当活动开始时,我试图在250dp的特定高度保持我的底页可见,并在单击按钮时全屏显示。不幸的是,活动开始时,我的底页不可见。 我使用的是一个持久的底部表单,而不是一个片段,因为我希望仍然使用窗口的其他部分。我该怎么办呢

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
  
    rootFrame = (RelativeLayout) findViewById(R.id.rootFrame);
    bottomlay = findViewById(R.id.bottom_sheet);
    layoutParams = bottomlay.getLayoutParams();
    bottomSheetBehavior = BottomSheetBehavior.from(bottomlay);
    bottomSheetBehavior.setPeekHeight(250);
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

     edtWhere = (ImageButton)findViewById(R.id.edtWhere);

       btnClose = (ImageButton)findViewById(R.id.btnClose);
        btnClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
           
        }
        });
       
    edtWhere.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            
                    int windowHeight = getWindowHeight();
                    if (layoutParams != null) {
                        layoutParams.height = windowHeight;
                    }
                    bottomlay.setLayoutParams(layoutParams);
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
              
        
         });
  @Override
   protected void onStart() {
    super.onStart();
    
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

   }
底板布局

   <?xml version="1.0" encoding="utf-8"?>
   <androidx.core.widget.NestedScrollView 
   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_gravity="bottom"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    app:behavior_hideable="false"
    app:behavior_peekHeight="250dp"
    android:id="@+id/bottom_sheet"
    android:background="@color/white"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

     <ImageButton
      android:id="@+id/btnClose"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/com_facebook_close"
      android:background="@color/transparent"
      android:layout_margin="20dp"/>

    </androidx.core.widget.NestedScrollView>

所以我找到了问题的原因。我不应该将
layout\u gravity
设置为我的
bottomsheet
布局。我已经改正了

 <androidx.core.widget.NestedScrollView 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:minHeight="250dp"
    app:behavior_hideable="false"
    app:behavior_peekHeight="250dp"
    android:id="@+id/bottom_sheet"
    android:background="@color/white"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

 </androidx.core.widget.NestedScrollView>