请帮我配置我的Dialog Fragment,我希望它在屏幕中央但是让Gravity.CENTER没有帮助。
以下是我使用的代码:
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);
我的问题是如何将其置于中心位置并轻微移动到底部 任何帮助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 & 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)
将以下属性添加到RelativeLayout
android:gravity="center"