2017-08-10 58 views
1

私のアクティビティでBottomSheetDialogFragmentを使用しています。このダイアログは縦向きモードで全高を表示しますが、ランドスケープモードに切り替えると表示しません。BottomSheetDialogFragmentがランドスケープモードで完全な高さを表示しない

Portrait Mode

Landscape Mode

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     CustomBottomSheetDialog customBottomSheetDialog = new CustomBottomSheetDialog(); 
     customBottomSheetDialog.show(getSupportFragmentManager(),customBottomSheetDialog.getTag()); 
    } 
} 

CustomBottomSheetDialog

風景モードで0
public class CustomBottomSheetDialog extends BottomSheetDialogFragment { 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     return View.inflate(getContext(), R.layout.view_config, null); 
    } 
} 

CustomBottomSheetDialogレイアウト

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:background="#fdf107" 
       android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="196dp" 
     android:gravity="center" 
     android:textColor="@color/colorAccent" 
     android:text="BottomSheetDialogFragment"/> 

</LinearLayout> 

、私は、全体のコンテンツを見るためにBottomSheetDialogFragmentをドラッグする必要があります。

+0

(http://issuetracker.google.com/issues/37083487)のとおりです。 "マテリアルデザインガイドラインでは、底部シートの上の領域が19:6の高さで底部シートがはがす必要があります。ランドスケープスクリーンは16:9よりも短いので、スペックの最小高さで覗いています。 " – Bracadabra

答えて

2

この問題の解決方法は次のとおりです。

@Override 
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      BottomSheetDialog dialog = (BottomSheetDialog) getDialog(); 
      FrameLayout bottomSheet = (FrameLayout) 
      dialog.findViewById(android.support.design.R.id.design_bottom_sheet); 
      BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet); 
      behavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
      behavior.setPeekHeight(0); 
     } 
    }); 
} 
+0

解決に感謝 –

+1

イベントが発生すると、リスナーの登録を忘れないようにしてください。 –

関連する問題