2016-07-02 55 views
0

不完全在右側我試圖將我的DialogFragment完全放在手機的右側。奇怪的是,它以前工作過,但我不知道我到底做了什麼,但我知道這是可能的。DialogFragment與Gravity.Right

正如您在圖片中看到的那樣,DialogFragment和屏幕右側之間有一點空間。我根本不想要那個空間。片段必須完全位於右側。

enter image description here

我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(); 

    } 
} 

爲dialogfragment佈局:

<?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> 
+1

也許這個回答可以幫助你:http://stackoverflow.com/questions/18536439/dialogfragment-fullscreen-shows-padding-on-sides –

+0

@FrancisStraccia感謝的人!它幫助! – Muddz

回答

0

我固定我的問題與接受的答案這個簡單的解決方案: https://stackoverflow.com/a/18554868/5366495

<style name="CustomDialog" parent="Theme.AppCompat.Light.NoActionBar" > 
    <item name="android:windowBackground">@color/white</item> 
    <item name="android:windowIsFloating">true</item> 
</style>