My Dialog的布局是一个Scrollview,有一些Textviews和一些EditText,但当我打开软键盘在EditText中输入内容时,键盘与我的视图重叠并且不滚动。
我尝试了很多解决方案,例如将fillViewPort设置为true并将LinearLayout设置为Scrollview的孩子,但没有任何对我有用。任何帮助将不胜感激。
我的XML代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relative_layout"
android:padding="@dimen/margin_xsmall">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/options"
android:gravity="center"
android:layout_centerHorizontal="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spinner_height"
android:id="@+id/spa_section"
android:gravity="center"
android:background="@drawable/border_transparent"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginRight="@dimen/margin_xsmall">
<TextView
android:layout_width="@dimen/text_width"
android:layout_height="@dimen/spinner_height"
android:id="@+id/spa"
android:text="@string/spa"
android:textColor="@color/white"
android:gravity="center"
android:background="@color/transparent_grey"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:paddingTop="@dimen/margin_xxsmall"
android:paddingBottom="@dimen/margin_xxsmall"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="@dimen/spinner_height"
android:id="@+id/spa_qty"
android:hint="@string/no_of_spa"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:inputType="number"
android:textSize="@dimen/textsize_medium"
android:background="@android:color/transparent"
android:ellipsize="start"
android:gravity="start|center_vertical"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:maxLines="1"
android:layout_toEndOf="@+id/spa"
android:layout_toRightOf="@+id/spa"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginStart="@dimen/margin_xsmall"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spinner_height"
android:id="@+id/restro_section"
android:gravity="center"
android:background="@drawable/border_transparent"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginRight="@dimen/margin_xsmall"
android:layout_below="@+id/spa_section"
android:layout_marginTop="@dimen/margin_xsmall">
<TextView
android:layout_width="@dimen/text_width"
android:layout_height="@dimen/spinner_height"
android:id="@+id/restro"
android:text="@string/restro"
android:textColor="@color/white"
android:gravity="center"
android:background="@color/transparent_grey"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:paddingTop="@dimen/margin_xxsmall"
android:paddingBottom="@dimen/margin_xxsmall"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="@dimen/spinner_height"
android:id="@+id/restro_qty"
android:hint="@string/no_of_restro"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:inputType="number"
android:textSize="@dimen/textsize_medium"
android:background="@android:color/transparent"
android:ellipsize="start"
android:gravity="start|center_vertical"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:maxLines="1"
android:layout_toEndOf="@+id/restro"
android:layout_toRightOf="@+id/restro"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginStart="@dimen/margin_xsmall"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spinner_height"
android:id="@+id/bar_section"
android:gravity="center"
android:background="@drawable/border_transparent"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginRight="@dimen/margin_xsmall"
android:layout_below="@+id/restro_section"
android:layout_marginTop="@dimen/margin_xsmall">
<TextView
android:layout_width="@dimen/text_width"
android:layout_height="@dimen/spinner_height"
android:id="@+id/bar"
android:text="@string/bar"
android:textColor="@color/white"
android:gravity="center"
android:background="@color/transparent_grey"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:paddingTop="@dimen/margin_xxsmall"
android:paddingBottom="@dimen/margin_xxsmall"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="@dimen/spinner_height"
android:id="@+id/bar_qty"
android:hint="@string/no_of_bar"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:inputType="number"
android:textSize="@dimen/textsize_medium"
android:background="@android:color/transparent"
android:ellipsize="start"
android:gravity="start|center_vertical"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:maxLines="1"
android:layout_toEndOf="@+id/bar"
android:layout_toRightOf="@+id/bar"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginStart="@dimen/margin_xsmall"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spinner_height"
android:id="@+id/conference_room_section"
android:gravity="center"
android:background="@drawable/border_transparent"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginRight="@dimen/margin_xsmall"
android:layout_below="@+id/bar_section"
android:layout_marginTop="@dimen/margin_xsmall">
<TextView
android:layout_width="@dimen/text_width"
android:layout_height="@dimen/spinner_height"
android:id="@+id/conference_room"
android:text="@string/conference"
android:textColor="@color/white"
android:gravity="center"
android:background="@color/transparent_grey"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:paddingTop="@dimen/margin_xxsmall"
android:paddingBottom="@dimen/margin_xxsmall"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="@dimen/spinner_height"
android:id="@+id/conference_room_qty"
android:hint="@string/conference_rooms"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:inputType="number"
android:textSize="@dimen/textsize_medium"
android:background="@android:color/transparent"
android:ellipsize="start"
android:gravity="start|center_vertical"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:maxLines="1"
android:layout_toEndOf="@+id/conference_room"
android:layout_toRightOf="@+id/conference_room"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginStart="@dimen/margin_xsmall"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spinner_height"
android:gravity="center"
android:background="@drawable/border_transparent"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginRight="@dimen/margin_xsmall"
android:layout_below="@+id/conference_room_section"
android:layout_marginTop="@dimen/margin_xsmall">
<TextView
android:layout_width="@dimen/text_width"
android:layout_height="@dimen/spinner_height"
android:id="@+id/banquet"
android:text="@string/banquet"
android:textColor="@color/white"
android:gravity="center"
android:background="@color/transparent_grey"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:paddingTop="@dimen/margin_xxsmall"
android:paddingBottom="@dimen/margin_xxsmall"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="@dimen/spinner_height"
android:id="@+id/banquet_qty"
android:hint="@string/banquet_halls"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:inputType="number"
android:textSize="@dimen/textsize_medium"
android:background="@android:color/transparent"
android:ellipsize="start"
android:gravity="start|center_vertical"
android:paddingLeft="@dimen/margin_xsmall"
android:paddingRight="@dimen/margin_xsmall"
android:maxLines="1"
android:layout_toEndOf="@+id/banquet"
android:layout_toRightOf="@+id/banquet"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginStart="@dimen/margin_xsmall"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="@+id/options"
android:layout_marginTop="@dimen/margin_xsmall"
android:layout_centerHorizontal="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ok"
android:text="@string/ok"
android:textAllCaps="false"
style="@style/LightGreenButton"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
我的Java代码
final Dialog itemDialog = new Dialog(QuestionnaireActivity.this);
itemDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
//dialog.getWindow().setWindowAnimations(R.style.ZoomOutZoomInDialogAnim);
itemDialog.setContentView(R.layout.dialog_q6_options);
itemDialog.setCancelable(true);
itemDialog.setCanceledOnTouchOutside(true);
//dialog.getWindow().setBackgroundDrawableResource(R.color.white);
//dialog.getWindow().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.transparent_light)));
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int DialogWidth;
int DialogHeight;
DialogWidth = (int) (size.x * 0.95);
DialogHeight = WindowManager.LayoutParams.WRAP_CONTENT;
itemDialog.getWindow().setLayout(DialogWidth, DialogHeight);
itemDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
itemDialog.show();