[英]Layout changes when keyboard appears
I have created a layout with edit boxes ,textfields,buttons and images etc. But when i try to type something in my edit box the keyboard appears and my layout changes horribly .how can i fix this? 我已经创建了具有编辑框,文本字段,按钮和图像等的布局。但是,当我尝试在编辑框中键入内容时,键盘会出现并且布局发生可怕的变化。我该如何解决?
before keyboard appears 在键盘出现之前
after keyboard appears 键盘出现后
my layout 我的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/contactus_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/cinema_contactus"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dp" />
<EditText
android:id="@+id/contactus_name_edittext"
android:layout_width="340dp"
android:layout_height="40dp"
android:layout_above="@+id/contactus_email_edittext"
android:layout_alignLeft="@+id/contactus_email_edittext"
android:layout_alignRight="@+id/contactus_email_edittext"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:hint="Name"
android:textSize="12sp" />
<EditText
android:id="@+id/contactus_email_edittext"
android:layout_width="340dp"
android:layout_height="40dp"
android:layout_above="@+id/contactus_message_edittext"
android:layout_marginBottom="20dp"
android:layout_toRightOf="@+id/fax"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:hint="E-mail"
android:textSize="12sp" />
<EditText
android:id="@+id/contactus_message_edittext"
android:layout_width="340dp"
android:layout_height="115dp"
android:layout_above="@+id/contactus_submit_button"
android:layout_alignLeft="@+id/contactus_email_edittext"
android:layout_alignRight="@+id/contactus_email_edittext"
android:layout_marginBottom="20dp"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:gravity="top|left"
android:hint="Message"
android:textSize="12sp" />
<Button
android:id="@+id/contactus_submit_button"
android:layout_width="125dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/mybutton"
android:text="@string/submit"
android:layout_marginBottom="30dp"
android:layout_marginTop="20dp"
android:textSize="14dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<ImageView
android:id="@+id/emailedit"
android:layout_width="45dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/contactus_email_edittext"
android:layout_toLeftOf="@+id/contactus_email_edittext"
android:src="@drawable/emailtop" />
<ImageView
android:id="@+id/nameedit"
android:layout_width="45dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/contactus_name_edittext"
android:layout_toLeftOf="@+id/contactus_name_edittext"
android:src="@drawable/nametop" />
<ImageView
android:id="@+id/messageedit"
android:layout_width="45dp"
android:layout_height="115dp"
android:layout_alignTop="@+id/contactus_message_edittext"
android:layout_toLeftOf="@+id/contactus_message_edittext"
android:src="@drawable/messagetop" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/contactus_submit_button"
android:layout_below="@+id/contactus_email_edittext"
android:orientation="horizontal" >
</LinearLayout>
<ImageView
android:id="@+id/fax"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_alignTop="@+id/contactus_telephone2"
android:layout_toLeftOf="@+id/contactus_telephone2"
android:layout_marginTop="3dp"
android:src="@drawable/fax" />
<ImageView
android:id="@+id/email"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_alignTop="@+id/contactus_email"
android:layout_toLeftOf="@+id/contactus_email"
android:layout_marginTop="3dp"
android:src="@drawable/message" />
<ImageView
android:id="@+id/telephone"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_alignTop="@+id/contactus_telephone1"
android:layout_toLeftOf="@+id/contactus_telephone1"
android:layout_marginTop="3dp"
android:src="@drawable/call" />
<ImageView
android:id="@+id/addresspointer"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_alignLeft="@+id/telephone"
android:layout_alignTop="@+id/contactus_address"
android:layout_marginTop="3dp"
android:src="@drawable/pointer" />
<TextView
android:id="@+id/contactus_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/contactus_submit_button"
android:layout_centerHorizontal="true"
android:text="@string/cinema_contactus_address"
android:textColor="#000000"
android:lineSpacingExtra="5dp"
android:textSize="14sp"
android:layout_marginTop="25dp" />
<TextView
android:id="@+id/contactus_telephone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/contactus_address"
android:layout_below="@+id/contactus_address"
android:text="@string/cinema_contactus_telephone1"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:textSize="14sp" />
<TextView
android:id="@+id/contactus_telephone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/telephone"
android:layout_toRightOf="@+id/telephone"
android:text="@string/cinema_contactus_telephone2"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:textSize="14sp" />
<TextView
android:id="@+id/contactus_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/contactus_telephone2"
android:layout_below="@+id/contactus_telephone1"
android:text="@string/cinema_contactus_email"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:textSize="14sp" />
</RelativeLayout>
try this 尝试这个
inside onCreate write 里面onCreate写
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Ok found the answer 确定找到答案了
i just had to add the following in my activity in manifest 我只需要在清单中的活动中添加以下内容
android:windowSoftInputMode="adjustPan" 机器人:windowSoftInputMode = “adjustPan”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.