2016-09-23 44 views
1

私はButtonSheetDialogFragmentレイアウトで余白を設定しようとしましたが、機能しませんでした。私はプログラム的にレイアウトからマージンを設定し、しようとしたが、これは私のXMLファイルlayout_bts_item.xmlButtomSheetDialogFragment Androidに左右の余白を設定する方法は?

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="10dp" 
    android:background="#00000000"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    </LinearLayout> 
</FrameLayout> 

でその同じ結果 を持っているあなたが設定完了したらこれは私のJavaコード

 public class ButtomSheetFragment extends BottomSheetDialogFragment { 

     private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() { 
      @Override 
      public void onStateChanged(@NonNull View bottomSheet, int newState)  { 
       if (newState == BottomSheetBehavior.STATE_HIDDEN) { 
        dismiss(); 
       } 

      } 

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

     @Override 
     public void setupDialog(Dialog dialog, int style) { 
      super.setupDialog(dialog, style); 

      View contentView = View.inflate(getContext(),   R.layout.layout_bts_item, null); 
      dialog.setContentView(contentView); 
      CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams(); 
      CoordinatorLayout.Behavior behavior = params.getBehavior(); 
      if (behavior != null && behavior instanceof BottomSheetBehavior) { 
       ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback); 
       int height = LayoutUtils.getScreenHeight(getActivity()); 
       double desiredHeight = (0.85 * height); 
       ((BottomSheetBehavior) behavior).setPeekHeight((int) desiredHeight); 
       contentView.getLayoutParams().height = (int) desiredHeight; 
       ((FrameLayout.LayoutParams) contentView.getLayoutParams()).leftMargin = 100; 
      } 
     } 
    } 
+0

「ButtonSheetDialogFragment」とは何ですか? –

+0

また、何を試しましたか?何が起こった? –

+0

ButtonSheetDialogFragment についてこれを確認してくださいhttps://developer.android.com/reference/android/support/design/widget/BottomSheetDialogFragment.html –

答えて

0

コールrequestLayout()ですマージンあなたのケースでは

、左マージンを追加した後

contentView.requestLayout(); 

のようなもの。

+0

は動作しません:( –

関連する問題