簡體   English   中英

單擊文本輸入之一以調出鍵盤時,使背景圖像不“擠壓”

[英]Getting the background image to not “squash” when one of the text input's is clicked to bring up the keyboard

所以我是編碼android的初學者,通常我可以在google上找到我的解決方案,但是這次我沒有運氣。 我制作了一個具有兩個活動的應用程序(一個登錄屏幕,該屏幕還具有一個指向注冊屏幕的注冊按鈕),在初始登錄屏幕上,單擊一個文本輸入可擠壓背景圖像,以使其基本適合鍵盤占據某些屏幕時產生的較小空間。 真煩人。

很抱歉粘貼這么大的代碼塊,但是作為一個初學者,我不確定該代碼的哪一部分是相關的,因此我已經包含了整個xml。 謝謝!

哦,再說一次-我不能太強調我完全是菜鳥-因此,請提供任何答案,以明確說明我應該更改/包括的代碼以及在哪個文件中以及該文件的位置嗎?

<?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 Manifest文件中,嘗試為MainActivity添加以下屬性:

<activity
            android:name=".MainActivity"
            android:windowSoftInputMode="adjustPan">
...
</activity>

當出現軟鍵盤但活動窗口未調整大小時,將使視圖平移。 看看那有什么區別。 如果調整大小效果更好,則可以添加"adjustResize"代替"adjustPan"屬性。 希望兩個人中的一個能為您解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM