Android DialogFragment在重力作用下不完全在右侧,对吗

Android DialogFragment在重力作用下不完全在右侧,对吗,android,android-layout,Android,Android Layout,我正试图将我的对话框片段完全放在手机的右侧。奇怪的是,它以前起作用了,但我不知道我到底做了什么,但我知道这是可能的 如图所示,对话框片段和屏幕右侧之间有少量空间。我根本不想要那个空间。碎片必须完全在右边 我的DialogFragment类: public class FontFragment extends DialogFragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nulla

我正试图将我的
对话框片段
完全放在手机的右侧。奇怪的是,它以前起作用了,但我不知道我到底做了什么,但我知道这是可能的

如图所示,
对话框片段
和屏幕右侧之间有少量空间。我根本不想要那个空间。碎片必须完全在右边

我的DialogFragment类:

public class FontFragment extends DialogFragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fontmenu, container);
    recyclerView = (RecyclerView) v.findViewById(R.id.fontmenuRcv);

    recyclerView.setHasFixedSize(true);

    FontMenuAdapter fontsAdapter = new FontMenuAdapter(Font.initFonts(getContext()), editText, getContext(), editText.getSelectionStart(), editText.getSelectionEnd(), this);
    recyclerView.setAdapter(fontsAdapter);

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(linearLayoutManager);

    return v;
}

@Override
public void onResume() {

    getDialog().getWindow().setGravity(Gravity.RIGHT|Gravity.BOTTOM);

    super.onResume();

  }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fontmenuRcv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>
对话框片段的布局:

public class FontFragment extends DialogFragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fontmenu, container);
    recyclerView = (RecyclerView) v.findViewById(R.id.fontmenuRcv);

    recyclerView.setHasFixedSize(true);

    FontMenuAdapter fontsAdapter = new FontMenuAdapter(Font.initFonts(getContext()), editText, getContext(), editText.getSelectionStart(), editText.getSelectionEnd(), this);
    recyclerView.setAdapter(fontsAdapter);

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(linearLayoutManager);

    return v;
}

@Override
public void onResume() {

    getDialog().getWindow().setGravity(Gravity.RIGHT|Gravity.BOTTOM);

    super.onResume();

  }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fontmenuRcv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>

我根据公认的答案,用这个简单的解决方案解决了我的问题:


@颜色/白色
真的

也许这个答案可以帮助你:@FrancisStraccia谢谢你,伙计!这有帮助!