-1

activity.xml嗨,我在文件中有以下布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_change_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
tools:context="com.kdpl.motodriver.ChangePassword">
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar1"
    android:layout_width="fill_parent"
    android:layout_height="58dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:titleTextColor="#ffffff">
    <Button
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:background="@drawable/back_arrow" android:onClick="onBackPressed" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/change_password_header"
        android:layout_gravity="center"
        android:id="@+id/toolbar_title"
        style="@style/TitleStyle"/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_below="@+id/toolbar1"
    android:id="@+id/txt1">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:id="@+id/txtOldPIN"
        android:hint="@string/txt_old_pin"
        android:maxLength="4"
        android:paddingLeft="10dp"
        android:textColor="#ffffff"
        android:inputType="numberPassword"
        android:textColorHint="@color/lightGray"
        android:gravity="center_vertical"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_below="@+id/txt1"
    android:id="@+id/txt2">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:paddingLeft="10dp"
        android:textColor="#ffffff"
        android:id="@+id/txtNewPin"
        android:inputType="numberPassword"
        android:maxLength="4"
        android:hint="@string/txt_new_pin"
        android:textColorHint="@color/lightGray"
        android:gravity="center_vertical"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_below="@+id/txt2"
    android:id="@+id/txt3">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:paddingLeft="10dp"
        android:id="@+id/txtConfirmPin"
        android:inputType="numberPassword"
        android:maxLength="4"
        android:textColor="#ffffff"
        android:layout_below="@+id/txt2"
        android:hint="@string/txt_confirm_new_pin"
        android:textColorHint="@color/lightGray"
        android:gravity="center_vertical"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentBottom="true">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnChangePIN"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/txt3"
        style="@style/buttonStyle"
        android:text="@string/txt_change_pin"
        android:enabled="false"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnCancelPIN"
        android:layout_marginTop="20dp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/btnChangePIN"
        style="@style/buttonStyle"
        android:text="@string/btn_cancel_text" />
</LinearLayout>

我在中添加了以下行Manifest.xml

  <activity android:name=".ChangePassword"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        />

但是Buttons align parent bottom当键盘打开时隐藏。布局不会自行调整大小。

我错过了什么?

更新视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_change_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
tools:context="com.kdpl.motodriver.ChangePassword">
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar1"
    android:layout_width="fill_parent"
    android:layout_height="58dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:titleTextColor="#ffffff">
    <Button
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:background="@drawable/back_arrow" android:onClick="onBackPressed" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/change_password_header"
        android:layout_gravity="center"
        android:id="@+id/toolbar_title"
        style="@style/TitleStyle"/>
</android.support.v7.widget.Toolbar>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/toolbar1">
    <LinearLayout
        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"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/toolbar1"
            android:id="@+id/txt1">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:id="@+id/txtOldPIN"
                android:hint="@string/txt_old_pin"
                android:maxLength="4"
                android:paddingLeft="10dp"
                android:textColor="#ffffff"
                android:inputType="numberPassword"
                android:textColorHint="@color/lightGray"
                android:gravity="center_vertical"/>
        </android.support.design.widget.TextInputLayout>
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/txt1"
            android:id="@+id/txt2">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:paddingLeft="10dp"
                android:textColor="#ffffff"
                android:id="@+id/txtNewPin"
                android:inputType="numberPassword"
                android:maxLength="4"
                android:hint="@string/txt_new_pin"
                android:textColorHint="@color/lightGray"
                android:gravity="center_vertical"/>
        </android.support.design.widget.TextInputLayout>
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/txt2"
            android:id="@+id/txt3">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:paddingLeft="10dp"
                android:id="@+id/txtConfirmPin"
                android:inputType="numberPassword"
                android:maxLength="4"
                android:textColor="#ffffff"
                android:layout_below="@+id/txt2"
                android:hint="@string/txt_confirm_new_pin"
                android:textColorHint="@color/lightGray"
                android:gravity="center_vertical"/>
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>
</ScrollView>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="10dp"
    android:layout_alignParentBottom="true">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnChangePIN"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/txt3"
        style="@style/buttonStyle"
        android:text="@string/txt_change_pin"
        android:enabled="false"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnCancelPIN"
        android:layout_marginTop="20dp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/btnChangePIN"
        style="@style/buttonStyle"
        android:text="@string/btn_cancel_text" />
</LinearLayout>

我已经更新了我的视图以添加scrollviewtoolbar和之间buttons。我还getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);按照建议添加了我的活动。它有效但并不完美。现在Buttons重叠视图scroll view。附上图片我的应用图片

4

5 回答 5

1

另一个答案是添加

android:windowSoftInputMode="adjustResize"

在您的根布局中

于 2017-04-13T07:16:49.693 回答
1

添加父布局是滚动视图

   <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
   </ScrollView >
于 2017-04-13T07:14:21.773 回答
0

为什么不使用CoordinateLayout作为父布局。如果它适用于零食,它也必须适用于键盘

于 2017-04-13T07:17:38.010 回答
0

在您的活动中添加此代码:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
于 2017-04-13T07:41:49.413 回答
-1

请使用 adjustPan 代替 adjustResize 如下:

<activity android:name=".ChangePassword"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" />
于 2017-04-13T07:15:11.273 回答