2017-01-26 29 views
0

请帮我配置我的对话框片段,我希望它在屏幕中间,但是使Gravity.CENTER没有帮助。配置DialogFragment的位置

这里是我的工作代码:

getDialog().getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP); 
WindowManager.LayoutParams param = getDialog().getWindow().getAttributes(); 
param.width = LayoutParams.MATCH_PARENT; 
param.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE; 
param.x = 100; 
param.y = 100; 

getDialog().getWindow().setAttributes(p); 

但如u图像看到这个心不是很好看 enter image description here

我queastion就是如何借此来中心,也是移动略低至底部 任何帮助approciate

编辑:这是与屏幕上的所有项目我的布局文件

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="30dp"> 
    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:gravity="center" 
     android:text="FEEDBACK &amp; CONTACT" 
     android:textAppearance="@style/Text.Medium" 
     android:textColor="@color/black" /> 
    <TextView 
     android:id="@+id/text2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_below="@+id/text" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="54dp" 
     android:gravity="center" 
     android:text="Got some ideas? Need some help?\n Send us a note!" 
     android:textColor="@color/black" /> 
    <EditText 
     android:id="@+id/editText" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:hint="Type a message here" 
     android:layout_alignTop="@+id/spinnerContactAndFeedback" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="28dp" 
     android:ems="10" 
     android:gravity="center" 
     android:inputType="textMultiLine" /> 
    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/editText" 
     android:layout_centerHorizontal="true" 
     android:layout_margin="6dp" 
     android:layout_marginTop="56dp" 
     android:gravity="center" 
     android:text="Help us improve Spontime! We will appreciate\n your rate and review!" 
     android:textColor="@color/black" /> 
    <TextView 
     android:id="@+id/rateButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/green_background" 
     android:gravity="center" 
     android:text="RATE" 
     android:textAllCaps="true" 
     android:layout_centerHorizontal="true" 
     android:textColor="@color/white" 
     android:textSize="16sp" 
     android:textStyle="bold" 
     android:layout_below="@+id/textView3" /> 
    <FrameLayout 
     android:id="@+id/send_mail_button" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/bottom_sheet_peek_height" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_gravity="bottom|center_horizontal" 
     android:layout_marginBottom="-6dp" 
     android:scaleX="@dimen/login_min_scale" 
     android:scaleY="@dimen/login_min_scale"> 
     <Button 
      android:id="@+id/button_send" 
      style="@style/CurvedView.Login.Button" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/bottom_sheet_btn_height" 
      android:layout_gravity="bottom" 
      android:text="@string/send" 
      android:textColor="@color/white" /> 
    </FrameLayout> 
    <Spinner 
     android:id="@+id/spinnerContactAndFeedback" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/text2" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="22dp" 
     android:gravity="center" 
     android:spinnerMode="dialog" /> 
</RelativeLayout> 
+0

你的对话几乎是全屏幕。您可以考虑首先更改“发送”按钮的位置。之后,重心将正常工作。 –

+0

添加您的布局文件。 – W4R10CK

+0

我上传了布局文件 – Rodriquez

回答

0

添加以下的属性到你的RelativeLayout

android:gravity="center"