2016-04-22 94 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); 
    } 

achived全屏DialogFragment但我不知道如何设置对话框的高度,并保持它在屏幕的底部?

enter image description here

+0

你可以改变你的rootview的的LayoutParams的宽度/高度 – Blackbelt

+0

您可以使用底部片相同 –

+0

@BhaveshDesai底层可以包含菜单只? – Alex

回答

0

当您创建的片段你在哪里,你想要的片段布局将被添加到给状态的选项。

add(R.layout....) 

创建活动的布局是定义框的大小,然后简单地add方法更改为布局空的布局

add(R.layout.theNewlyCreatedLayoutWiththeRightSizeAndPosition) 
0

您可以使用onCreateDialog(捆绑savedInstance)方法创建对话框,然后设置位置。例如 -

@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

您可以使用Bottomsheet您的问题

Bottomsheet你也可以使用FragmentViews

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); 
}