11

가로 모드에서 아래쪽 시트 대화 상자를 표시 할 때 잘못된 동작이 나타납니다. 이 문제는 디자인 라이브러리의 24. + 버전에서 발생합니다. 아래 이미지에 따르면 하단 시트가 가로 방향으로 만 올바르게 표시되지 않습니다. 내 BottomSheetDialog 클래스를 사용하고 난이 튜토리얼을 따르고 : http://www.skholingua.com/blog/bottom-sheet-android, 내 게시 된 애플 리케이션에서 문제가 발생합니다.하단 시트 가로 방향 문제

나는 25. + 버전을 테스트했으며 문제가 해결되지 않았습니다. 풍경 24에서

오류, 25 + 도서관

Error In landscape

같은 예를 들어 23 + 도서관

same example in 23.+ Library

주요 활동에

,451,515,
public class MainActivity extends AppCompatActivity { 
CoordinatorLayout coordinatorLayout; 
private BottomSheetBehavior<View> mBottomSheetBehavior; 
private TextView textView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content); 
    textView = (TextView) findViewById(R.id.textView); 
    View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet); 

    //For your bottom sheet to be displayable, you need to create a BottomSheetBehavior. 
    //This is created by getting a reference to the container view and calling BottomSheetBehavior.from() on that container. 
    mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 

    mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { 
     @Override 
     public void onStateChanged(@NonNull View bottomSheet, int newState) { 
      switch (newState) { 
       case BottomSheetBehavior.STATE_DRAGGING: 
        break; 
       case BottomSheetBehavior.STATE_COLLAPSED: 
        mBottomSheetBehavior.setPeekHeight(0); 
        break; 
       case BottomSheetBehavior.STATE_EXPANDED: 
        break; 
       case BottomSheetBehavior.STATE_HIDDEN: 
        break; 
       case BottomSheetBehavior.STATE_SETTLING: 
        break; 
      } 
     } 

     @Override 
     public void onSlide(@NonNull View bottomSheet, float slideOffset) { 
     } 
    }); 

} 


public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.button1: 
      /** 
      * For persistent bottom sheet to work, your layout should contain a coordinator layout, 
      * and then in any child view of your coordinator layout, you can make it as a persistent bottom sheet 
      * by adding a custom property app:layout_behavior and use behavior_peekHeight to define how much 
      * of the Bottom Sheet you want visible. 
      */ 
      textView.setText(R.string.dynamic_persistent_txt); 
      mBottomSheetBehavior.setPeekHeight(300); 
      mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
      break; 
     case R.id.button2: 
      /** 
      * You can also display a Dialog in place of a View in the bottom sheet. 
      * To do this, get the view from getLayoutInflater and pass it setContentView of the Dialog. 
      */ 
      View view = getLayoutInflater().inflate(R.layout.bottom_sheet_layout, null); 
      TextView textView = (TextView) view.findViewById(R.id.textView); 
      textView.setText(R.string.dialog_modal_txt); 
      BottomSheetDialog dialog = new BottomSheetDialog(this); 
      dialog.setContentView(view); 
      dialog.show(); 
      break; 
     case R.id.button3: 
      /** 
      * You can also display a Fragment in place of a View in the bottom sheet. 
      * To do this, you class that extends BottomSheetDialogFragment. 
      */ 
      BottomSheetDialogFragment bottomSheetDialogFragment = new BottomSheetDialogFragmentExample(); 
      bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag()); 
      break; 
    } 
} 

activity_main.xml

<android.support.design.widget.CoordinatorLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingTop="24dp" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:onClick="onClick" 
     android:text="Dynamic BottomSheet" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:onClick="onClick" 
     android:text="BottomSheetDialog" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:onClick="onClick" 
     android:text="BottomSheetDialogFragment" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="4dp" 
    android:minHeight="120dp" 
    android:orientation="vertical" 
    android:padding="@dimen/activity_vertical_margin" 
    app:behavior_peekHeight="120dp" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

    <include layout="@layout/bottom_sheet_layout" /> 

</LinearLayout> 

</android.support.design.widget.CoordinatorLayout> 

bottom_sheet_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/CreamyGreen" 
android:orientation="vertical"> 


<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/static_persistent_txt" 
    android:padding="16dp" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="@android:color/white" /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="16dp" 
    android:text="@string/ipsum" 
    android:textColor="@android:color/white" 
    android:textSize="16sp" /> 
</LinearLayout> 
+0

비록 그것이 틀린 것처럼 보이고 어리석은 느낌이 들지만, 이것은 의도에 의한 것이라고 생각합니다. AUTO 높이 설정은 하단 시트가 16 : 9 비율의 키 라인을 넘어서는 것을 방지합니다 .... 가로로 어리석은 모습을 보입니다 ... – Zordid

+5

Android 이슈 트래커에서 문제를 열었으며 문제를 해결할 수있는 방법을 받았습니다. https://code.google.com/p/android/issues/detail?id=231964#c6 페이지를 참조하십시오. –

답변

4

이 주변의 일이다. (참고 :이 코드는 활동에)

View sheetView;//class level variable 

private void setUpBottomSheetDialog() { 

    bottomSheetDialog = new BottomSheetDialog(this); 

    LayoutInflater inflater = LayoutInflater.from(this); 
    sheetView = inflater.inflate(R.layout.bottom_sheet_image_source, (ViewGroup) this.getWindow().getDecorView().getRootView(), false); 

    bottomSheetDialog.setContentView(sheetView); 

    BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) sheetView.getParent()); 

    bottomSheetDialog.setOnShowListener(dialogInterface -> { 
     mBehavior.setPeekHeight(sheetView.getHeight());//get the height dynamically 
    }); 
} 
0

구글의 사람이 의도 한대로 작동, 여기에 해결

분을 보인다 화면 높이 비율의 마법 일정이 있습니다에게 그대로이 폐쇄 (actualwidth 분명히 전화 풍경과 잘 작동하지 않습니다, themewidth)는, 따라서 (또한 가로 모드에서) 내가 다음을 수행합니다 BottomSheetDialogFragment 항상 완전히 확장 열 가지려면 더 큰 무언가

<style name="Theme.Main.Reader"> 
    ... 
    <item name="bottomSheetDialogTheme">@style/ReaderBottomSheelDialog</item> 
</style> 
<style name="ReaderBottomSheelDialog" parent="Theme.Design.BottomSheetDialog"> 
    <item name="bottomSheetStyle">@style/BottomSheetStyle</item> 
</style> 

<style name="BottomSheetStyle" parent="Widget.Design.BottomSheet.Modal"> 
    <item name="behavior_peekHeight">512dp</item> 
</style> 
0

에 우선합니다.

onCreateDialog에서 BottomSheetDialog 및 뷰를 만듭니다. 이 뷰를 BottomSheetDialog에 추가하면 BottomSheetBehavior.from()에서 뷰의 부모를 사용하여 BottomSheetBehavior를 얻을 수 있습니다.

그런 다음 BottomSheetDialogFragment의 onStart에서 STATE_EXPANDED와 함께 BottomSheetBehavior.setState를 호출합니다.

BottomSheetBehavior mBottomBehavior; 

public Dialog onCreateDialog(Bundle savedInstanceState) { 
    BottomSheetDialog dialog = new BottomSheetDialog(getContext()); 
    mBinding = SomeBinding.inflate(LayoutInflater.from(getContext())); 
    dialog.setContentView(mBinding.getRoot()); 
    mBottomBehavior = BottomSheetBehavior.from((View) mBinding.getRoot().getParent()); 
    return dialog; 
} 

public void onStart() { 
    super.onStart(); 
    mBottomBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
} 

이 정보가 도움이되기를 바랍니다.