部分 UI 屏幕向上

Partial UI screen up

在一个屏幕中,我在顶部有一个编辑文本(大的包含 space 用于 4-5 行),图像视图在其下方,提交按钮在底部。在键盘上它不应该隐藏我的提交按钮。

当键盘出现时,我可以使用 android:windowSoftInputMode="adjustResize" 调整 window 的大小,这样我就不会隐藏提交按钮,但它也会调整我不想要的图像大小。

只有提交按钮应该在键盘可见且不调整图像大小的情况下向上移动。

我也试过框架布局,但没有试过,可能是我试错了。我们将不胜感激。

应用这个,让我知道它是否还在发生。

activity_mian.xml

<ScrollView 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:layout_gravity="center_vertical|center_horizontal"
    android:background="@drawable/xxx.jpg"
    android:orientation="vertical"
    tools:context=".LoginActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="190dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/logo_app" />

        <EditText
            android:id="@+id/edtEmail"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/login_textbox"
            android:ems="10"
            android:hint="Email"
            android:imeOptions="actionNext"
            android:inputType="textEmailAddress"
            android:singleLine="true"
            android:textColor="#ffffff"
            android:textCursorDrawable="@null" />

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

            <EditText
                android:id="@+id/edtPassword"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_gravity="center_vertical|center_horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/login_textbox"
                android:ems="10"
                android:hint="Password"
                android:imeOptions="actionDone"
                android:inputType="textPassword"
                android:singleLine="true"
                android:textColor="#ffffff"
                android:textCursorDrawable="@null" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_alignParentTop="true"
                android:layout_alignRight="@+id/edtPassword"
                android:layout_marginTop="2dp" />
        </RelativeLayout>

        <CheckBox
            android:id="@+id/checkBox_remember"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp"
            android:button="@drawable/checkbox_selector"
            android:checked="true"
            android:focusable="false"
            android:focusableInTouchMode="true"
            android:text="  Remember Me"
            android:textColor="#ffffff" />    


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="10dp"
            android:orientation="vertical" >

            <Button
                android:id="@+id/btnLogin"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                        android:layout_gravity="top|center_vertical|center_horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@drawable/btn_login" />


        </LinearLayout>


    </LinearLayout>

</ScrollView>

将您的 Button、EditText 等设置在一个线性布局中,然后是一个父级 ScrollView。

另一件事是设置 android:windowSoftInputMode="stateAlwaysHidden" 在你的 java 文件里面你的 xml 文件绑定了 .

随着@jigs 回答的一些变化,我得到了它的工作和发布可能它可以帮助像我这样的人

1) 根布局在我的例子中是正常的相对布局。然后滚动视图内的滚动视图采用线性布局,其中指定编辑文本+图像视图。然后是底部按钮。

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:background="@android:color/white"
    android:orientation="vertical">

<ScrollView
    android:id="@+id/scrollViewNotScrollable"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/user_name_container">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:orientation="vertical"

        >

        <EditText
            android:id="@+id/input_feed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#00000000"
            android:ellipsize="start"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="start|center_vertical"
            android:hint="@string/feed_hint"
            android:imeActionLabel="Submit"
            android:imeOptions="actionSend"
       android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
            android:maxLines="5"
            android:minLines="3"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="25dp"
            android:textColor="@color/feed_sub_color"
            android:textColorHint="@color/light_gray"
            android:textCursorDrawable="@null" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp">
            <!--<ScrollView
                android:id="@+id/scroll"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:isScrollContainer="false"
                android:padding="4dp"

                android:layout_centerHorizontal="true"
                >-->
            <ImageView
                android:id="@+id/imgPreview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center"
                android:layout_marginBottom="20dp"
                android:layout_marginTop="20dp"
                android:adjustViewBounds="true"
                android:background="@android:color/white"
                android:elevation="5dp"
                android:padding="4dp"
                android:visibility="gone" />
            <!--</ScrollView>-->
            <ImageView
                android:id="@+id/close_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/imgPreview"
                android:layout_marginLeft="-45dp"
                android:layout_marginTop="-20dp"
                android:layout_toRightOf="@+id/imgPreview"
                android:elevation="5dp"
                android:paddingBottom="15dp"
                android:src="@drawable/closeimage"
                android:visibility="gone" />

        </RelativeLayout>
    </LinearLayout>
</ScrollView>

<RelativeLayout
    android:id="@+id/user_name_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:fitsSystemWindows="true">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />

    <EditText
        android:id="@+id/feed_user_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:background="@null"
        android:ellipsize="end"
        android:fontFamily="san-serif-condensed"
        android:padding="12dp"
        android:singleLine="true"
        android:text="sherry's phone"
        android:textColor="@android:color/black"
        android:textSize="@dimen/feed_name_size"
        android:visibility="gone" />

    <TextView
        android:id="@+id/feed_user_name_textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:background="@null"
        android:ellipsize="end"
        android:fontFamily="san-serif-condensed"
        android:padding="12dp"
        android:paddingLeft="20dp"
        android:singleLine="true"
        android:text="sherry's phone"
        android:textColor="@android:color/black"
        android:textSize="@dimen/feed_name_size" />

    <ImageView
        android:id="@+id/edit_name"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_gravity="end"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:paddingBottom="5dp"
        android:paddingTop="5dp"
        android:scaleType="centerInside"
        android:src="@drawable/editname" />

    <Button
        android:id="@+id/done"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/rounded_corner_update_block"
        android:fontFamily="san-serif-medium"
        android:text="Done"
        android:textColor="@android:color/white"
        android:visibility="gone" />
</RelativeLayout>

</RelativeLayout>

2)android:windowSoftInputMode="adjustResize" 在你的 manifest.xml

3) 在 java 代码中禁用滚动(可选)

    mScrollView.setOnTouchListener( new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) 
            {
                  return true;
            }
});