首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于安卓系统的软件键盘移动editTexts

用于安卓系统的软件键盘移动editTexts
EN

Stack Overflow用户
提问于 2015-05-01 23:49:22
回答 3查看 218关注 0票数 0

我正在尝试让editTexts和登录按钮在软键盘出来时向上移动,但我不希望背景被压缩(我很快就会添加一个图像)。我有一个ScrollView中的TextView(登录),两个EditTexts(电子邮件和密码)和登录按钮,因为我认为这可能会有所帮助,但我一直无法弄清楚任何事情。

http://i.imgur.com/vlYifc6.png

http://i.imgur.com/vlYifc6.png

这是xml

代码语言:javascript
复制
<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:id="@+id/textLayout">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Login"
                android:id="@+id/loginView"
                android:textSize="22dp"
                android:layout_above="@+id/textLayout"
                android:layout_centerHorizontal="true" />

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/emailTextfield"
                android:inputType="textEmailAddress"
                android:background="@android:drawable/edit_text"
                android:textColor="@android:color/primary_text_light"
                android:text="andresc1305@yahoo.com"
                android:hint="Email" />

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password"
                android:text="Andres123"
                android:background="@android:drawable/edit_text"
                android:textColor="@android:color/primary_text_light"
                android:ems="10"
                android:id="@+id/passwordTextfield" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="SIGN IN"
                android:background="@android:color/transparent"
                android:textSize="24dp"
                android:id="@+id/signinButton"
                android:layout_below="@+id/textLayout"
                android:layout_centerHorizontal="true"
                android:onClick="onSigninClick"/>
        </LinearLayout>
    </ScrollView>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Forgot your password?"
        android:background="@android:color/transparent"
        android:textSize="14dp"
        android:id="@+id/forgotButton"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="onPasswordRecoverClick"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Register"
        android:background="@android:color/transparent"
        android:textSize="14dp"
        android:id="@+id/registerButton"
        android:layout_alignTop="@+id/forgotButton"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:onClick="onRegisterClick"/>


</RelativeLayout>
EN

回答 3

Stack Overflow用户

发布于 2015-05-01 23:57:51

请看this的答案。简而言之,您的问题很可能通过在AndroidManifest.xml中的相关activityapplication元素中设置以下内容来解决:

代码语言:javascript
复制
android:windowSoftInputMode="adjustResize"
票数 0
EN

Stack Overflow用户

发布于 2015-05-07 06:49:31

@PPartisan

这里没有:

代码语言:javascript
复制
android:windowSoftInputMode="adjustResize"

http://i.imgur.com/tbNioU2.png

这是通过:

http://i.imgur.com/7ZePHjS.png

除了压缩,您还可以看到我的“忘记密码”和“注册”按钮,但我在ScrollView之外的XML中有这两个按钮。有没有办法在出现软键盘时向上滚动LinearLayout (其中包含登录(TextView)、电子邮件(EditText)、密码(EditText)和登录(按钮)?

zmilojko的回答似乎就是我想要做的,但他只说添加ScrollView,而不是添加之后要做什么。有没有什么东西我可以放在里面,使它在软键盘出现时向上移动?

票数 0
EN

Stack Overflow用户

发布于 2016-01-16 00:31:18

请看这个帖子,我想它可以帮助你

layout of the screen moves up when keyboard is displayed

或者尝试将以下代码放入您的xml中:

代码语言:javascript
复制
android:windowSoftInputMode="adjustPan" 

或者这个

代码语言:javascript
复制
android:windowSoftInputMode="adjustNothing"

似乎它在每种情况下的工作方式都不同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29990247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档