安卓。单击编辑文本时上推内容

标签 android android-edittext keyboard

我的 Activity 有一个登录表单。我需要这个逻辑:

http://www.clipular.com/c/6455748191322112.png?k=Xc28Y-FsMShuNpEXbWD5rpe6faY http://www.clipular.com/c/5414772807041024.png?k=k3TB9AiHEtdV8oh6G17Ag-MS2nI

我该怎么做?我尝试将 android:windowSoftInputMode="adjustPan" 设置为 list 中的 Activity 但这没有用。

我的布局:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/truck">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="@dimen/login_logo_width"
        android:layout_height="@dimen/login_logo_height"
        android:layout_marginTop="@dimen/login_logo_margin_top"
        android:layout_marginStart="@dimen/login_logo_margin_left"
        android:src="@drawable/logo_transfort_white"
        android:contentDescription="@string/logo_title"/>

    <TextView
        android:id="@+id/skip"
        style="@style/GrayText"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/default_text_height"
        android:layout_alignEnd="@id/logo"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="@dimen/skip_button_margin_right"
        android:layout_marginTop="@dimen/skip_button_margin_top"
        android:gravity="center"
        android:text="@string/skip" />

    <LinearLayout
        android:id="@+id/inputs"
        android:background="@drawable/login_buttons_background"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/inputs_block_margin_top"
        android:layout_marginStart="@dimen/inputs_block_margin_left_right"
        android:layout_marginEnd="@dimen/inputs_block_margin_left_right"
        android:layout_below="@id/logo"
        android:orientation="vertical"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true">

        <EditText
            android:id="@+id/login"
            android:layout_width="match_parent"
            android:layout_height="@dimen/default_text_height"
            android:layout_marginTop="@dimen/inputs_block_margin_left_right"
            android:layout_marginStart="@dimen/inputs_block_margin_left_right"
            android:background="@color/text_color_white_transparent"
            android:ems="16"
            android:hint="@string/login"
            style="@style/LoginInputs"/>

        <View
            android:id="@+id/inputs_line"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/login_line_height"
            android:layout_marginTop="@dimen/login_line_margin_top"
            android:layout_marginStart="@dimen/inputs_block_margin_left_right"
            android:layout_marginEnd="@dimen/inputs_block_margin_left_right"
            android:background="@color/line_color_white_capacity" />

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="@dimen/default_text_height"
            android:layout_marginTop="@dimen/login_line_margin_top"
            android:layout_marginStart="@dimen/inputs_block_margin_left_right"
            android:layout_marginBottom="@dimen/inputs_block_margin_left_right"
            android:background="@color/text_color_white_transparent"
            android:ems="16"
            android:hint="@string/password"
            android:inputType="textPassword"
            style="@style/LoginInputs" />

    </LinearLayout>

    <TextView
        android:id="@+id/forgot_password"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/default_text_height"
        android:layout_below="@id/inputs"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="@dimen/forgot_password_margin_top"
        android:layout_marginEnd="@dimen/inputs_block_margin_left_right"
        android:text="@string/forgot_password"
        android:gravity="center"
        style="@style/WhiteText" />

    <Button
        android:id="@+id/enter"
        android:background="@drawable/sigin_button_background"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/forgot_password"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="@dimen/inputs_block_margin_left_right"
        android:layout_marginEnd="@dimen/inputs_block_margin_left_right"
        android:layout_marginTop="@dimen/signin_button_margin_top"
        android:textColor="@android:color/white"
        android:text="@string/enter_text" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/enter"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/no_account"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/no_account_margin_left"
            android:layout_marginTop="@dimen/no_account_margin_top"
            android:text="@string/no_account"
            style="@style/GrayText"/>

        <TextView
            android:id="@+id/check_in"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/check_in_margin_left"
            android:layout_marginTop="@dimen/no_account_margin_top"
            android:text="@string/check_in"
            style="@style/WhiteText" />

    </LinearLayout>
</RelativeLayout>

最佳答案

ScrollView 作为父 Layout

<ScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true">

    <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical">

        // add here all your controls

   </LinearLayout>

</ScrollView>

比使用

android:windowSoftInputMode="adjustPan" 在你的 Activity 中

<activity
     android:name=".activity.TempActivity"
     android:windowSoftInputMode="adjustPan"
     android:theme="@style/AppTheme.NoActionBar"/>

关于安卓。单击编辑文本时上推内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46707580/

相关文章:

android - 在 gradle sync android studio 上跳过 prebuilt-library.mk

javascript - 我可以从 android 浏览器 JavaScript 中获取哪些信息?

android - EditText 不 wrap_content

windows - wxPython - 在没有窗口焦点的情况下捕获鼠标和键盘事件

android - 如何更改/重置处理程序后延迟时间?

java - 如何添加工具栏?

java - edittext可见意味着我如何检查android中的if条件

android - 根据两个或多个 EditText 字段中的输入启用/禁用按钮的优雅方式

linux - 用于按键的键盘脚本

javascript - : How to catch the Spacebar and the Enter key, 是否可访问鼠标左键?