单击其中一个文本输入以调出键盘时,使背景图像不 "squash"
Getting the background image to not "squash" when one of the text input's is clicked to bring up the keyboard
所以我是编码的初学者 android,通常我可以在 google 上找到我的解决方案,但这次我运气不好。我制作了一个包含两个活动的应用程序(一个登录屏幕,还有一个指向注册屏幕的注册按钮),在初始登录屏幕上,单击其中一个文本输入会挤压背景图像,使其基本上适合当键盘占据部分屏幕时创建较小的 space。挺烦人的。
很抱歉粘贴了这么大的代码块,但作为初学者,我不太确定这段代码的哪一部分是相关的,所以我已经包含了整个代码 xml。谢谢!
哦,再说一次 - 我不能强调我是一个完全的菜鸟 - 所以任何答案都请说明 crystal 清楚我应该 changing/including 和在什么代码中文件,以及该文件中的什么地方?
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/qlogoonwallpaper"
tools:context=".MainActivity">
<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:layout_marginBottom="48dp">
<LinearLayout
android:id="@+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="match_parent"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="@color/colorPrimaryDark"
android:text="@string/action_sign_in"
android:textAllCaps="false"
android:textColor="@android:color/background_light"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="-208dp"
android:ems="10"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="225dp"
android:background="@android:color/transparent"
android:text="@string/register_intro"
android:textAllCaps="false"
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
在 Android 清单文件中,尝试为您的 MainActivity 添加以下属性:
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan">
...
</activity>
当软键盘出现但 activity 的 window 未调整大小时,这会使视图平移。看看这是否有什么不同。如果调整大小效果更好,您可以添加 "adjustResize"
而不是 "adjustPan"
属性。希望两者之一能为您解决问题。
所以我是编码的初学者 android,通常我可以在 google 上找到我的解决方案,但这次我运气不好。我制作了一个包含两个活动的应用程序(一个登录屏幕,还有一个指向注册屏幕的注册按钮),在初始登录屏幕上,单击其中一个文本输入会挤压背景图像,使其基本上适合当键盘占据部分屏幕时创建较小的 space。挺烦人的。
很抱歉粘贴了这么大的代码块,但作为初学者,我不太确定这段代码的哪一部分是相关的,所以我已经包含了整个代码 xml。谢谢!
哦,再说一次 - 我不能强调我是一个完全的菜鸟 - 所以任何答案都请说明 crystal 清楚我应该 changing/including 和在什么代码中文件,以及该文件中的什么地方?
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/qlogoonwallpaper"
tools:context=".MainActivity">
<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:layout_marginBottom="48dp">
<LinearLayout
android:id="@+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="match_parent"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="@color/colorPrimaryDark"
android:text="@string/action_sign_in"
android:textAllCaps="false"
android:textColor="@android:color/background_light"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="-208dp"
android:ems="10"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="225dp"
android:background="@android:color/transparent"
android:text="@string/register_intro"
android:textAllCaps="false"
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
在 Android 清单文件中,尝试为您的 MainActivity 添加以下属性:
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan">
...
</activity>
当软键盘出现但 activity 的 window 未调整大小时,这会使视图平移。看看这是否有什么不同。如果调整大小效果更好,您可以添加 "adjustResize"
而不是 "adjustPan"
属性。希望两者之一能为您解决问题。