【发布时间】:2017-09-09 04:35:07
【问题描述】:
嗨,我在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>
我已更新我的视图以在 toolbar 和 buttons 之间添加 scrollview。我还按照建议在我的活动中添加了getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);。它有效但并不完美。现在Buttons 与scroll view 中的视图重叠。附上图片
【问题讨论】:
-
添加滚动会帮助你。
-
除了下面的布局外,还要在标签上方添加布局,以便您的滚动视图始终保持在两个指定视图之间
标签: android android-layout window-soft-input-mode