2016-04-22 3 views
2

私のアプリケーションでは、このようなDialogFragmentを作成するための要件が​​あります(画像 - 下部1/4画面に表示されます)。私はDialogFragment:プレースメントとディメンションの設定方法は?

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     int style = DialogFragment.STYLE_NO_TITLE; 
     int theme = android.R.style.Theme_Holo; 
     setStyle(style, theme); 
    } 

を通じてフルスクリーンDialogFragmentをachivedしている。しかし、私は、ダイアログボックスの高さを設定し、画面の一番下にそれを維持する方法がわかりませんか?

enter image description here

+0

あなたはあなたが唯一のメニューを含めることができ、同じ – Blackbelt

+0

あなたrootviewのLayoutParamsの幅/高さを変更することができています? –

+0

@BhaveshDesaiボトムシートのためのボトムシートを使用することができます – Alex

答えて

0

あなたはあなたがに追加するフラグメントレイアウトを配置したい場所を述べるためのオプションを与えているフラグメントを作成する場合。

add(R.layout....) 

あなたがにonCreateDialog(バンドルsavedInstance)メソッドを使用することができ、そのボックスの定義されたサイズでの活動のレイアウトに空のレイアウトを作成し、単純にそのレイアウトにaddメソッドを変更

add(R.layout.theNewlyCreatedLayoutWiththeRightSizeAndPosition) 
0

ダイアログを作成して、位置を設定します。例えば ​​-

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 

    // Make the dialog view ready 
    //LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); 
    //View v = layoutInflater.inflate(R.layout.dialog,null); 

    // Create the dialog 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    // Set the view in dialog 
    //builder.setView(v); 
    Dialog dialog = builder.create(); 

    // Set the dialog position 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); 

    wmlp.gravity = Gravity.BOTTOM| Gravity.CENTER; 
    wmlp.x = 100; //x position 
    wmlp.y = 100; //y position 


    return dialog; 
} 
0

あなたはまた、FragmentViews

Bottomsheet例を使用することができますBottomsheetでは、あなたの問題

ためBottomsheetを使用することができますhere

0

あるだけでなく、あなたは、単にOnCreateViewをオーバーライドそれを達成でき、必要に応じて手動でパラメータを設定します。ここで

は例

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { 

    Window window = getDialog().getWindow(); 

    // set gravity 
    window.setGravity(Gravity.BOTTOM|Gravity.CENTER); 

    // then set the values to where you want to position it 
    WindowManager.LayoutParams params = window.getAttributes(); 
    params.x = 300; 
    params.y = 100; 
    window.setAttributes(params); 
} 
関連する問題