你网上一搜,会发现网上噼里啪啦一堆都是说: 1)设置activity的android:windowSoftInputMode="adjustPan|stateHidden" 2) 或者 android:windowSoftInputMode="adjustResize|stateHidden" 3)或者getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 其实最简单粗暴的方法就是给根部局设置为 ScrollView <?xml version="1.0" encoding="utf-8"?> <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:background="@color/white" android:fadeScrollbars="true" android:fillViewport="true" android:focusable="true" android:focusableInTouchMode="true" tools:context=".act.main.LoginActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/dp_100" android:orientation="vertical" tools:ignore="MissingConstraints"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" tools:ignore="MissingConstraints,UseCompoundDrawables"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginStart="@dimen/dp_30" android:layout_marginEnd="@dimen/dp_10" android:src="@drawable/smile" tools:ignore="ContentDescription" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/welcome_121" android:textColor="@color/color_000000" android:textSize="@dimen/big_medium" android:textStyle="bold" /> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/dp_40" android:orientation="vertical" tools:ignore="MissingConstraints"> <com.guwu.androidvarys.widgets.ClearEditText android:id="@+id/mEtMobile" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/dp_30" android:layout_marginEnd="@dimen/dp_30" android:background="@drawable/et_line_bg" android:drawableRight="@drawable/ic_delete" android:hint="@string/inputAccount" android:paddingStart="@dimen/dp_8" android:textColorHint="@color/login_hin" android:textSize="@dimen/small" tools:ignore="Autofill,HardcodedText,LabelFor,RtlHardcoded,RtlSymmetry,TextFields" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/dp_24" android:orientation="horizontal"> <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="@dimen/dp_30" android:layout_marginEnd="@dimen/dp_30" android:layout_marginBottom="@dimen/dp_13" android:layout_weight="1"> <EditText android:id="@+id/mETRequireCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/edit_shape" android:hint="@string/auth_code" android:inputType="number" android:paddingStart="@dimen/dp_8" android:textColorHint="@color/login_hin" android:textSize="@dimen/small" tools:ignore="Autofill,HardcodedText,LabelFor,RtlSymmetry,TextFields" /> <EditText android:id="@+id/mEtPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/edit_shape" android:hint="@string/input_pwd" android:inputType="textPassword" android:paddingStart="@dimen/dp_8" android:textColorHint="@color/login_hin" android:textSize="@dimen/small" android:visibility="gone" tools:ignore="Autofill,HardcodedText,LabelFor,RtlSymmetry,TextFields" /> </RelativeLayout> <TextView android:id="@+id/tvAuthCode" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_marginEnd="@dimen/dp_46" android:text="@string/send_auth_code" android:textColor="@color/title_fans" android:textSize="@dimen/small" android:visibility="visible" tools:ignore="ObsoleteLayoutParam,RelativeOverlap" /> <TextView android:id="@+id/forgetPsd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="@dimen/dp_46" android:text="@string/forgetPsd" android:textColor="@color/title_fans" android:textSize="@dimen/small" android:visibility="gone" tools:ignore="RelativeOverlap" /> </LinearLayout> <View android:id="@+id/et_password_view" android:layout_width="match_parent" android:layout_height="@dimen/dp_1" android:layout_marginStart="@dimen/dp_30" android:layout_marginEnd="@dimen/dp_30" android:background="@color/login_view" /> <TextView android:id="@+id/mTVLogin" android:layout_width="match_parent" android:layout_height="@dimen/dp_50" android:layout_marginStart="@dimen/dp_30" android:layout_marginTop="@dimen/dp_39" android:layout_marginEnd="@dimen/dp_30" android:layout_marginBottom="@dimen/dp_16" android:background="@drawable/register_btn_bg" android:gravity="center" android:text="@string/login" android:textColor="@color/white" android:textSize="@dimen/big_seven" /> <Button android:id="@+id/tvRegister" android:layout_width="match_parent" android:layout_height="@dimen/dp_50" android:layout_gravity="center_vertical" android:layout_marginStart="@dimen/dp_30" android:layout_marginEnd="@dimen/dp_30" android:layout_marginBottom="@dimen/dp_20" android:background="@drawable/register_button" android:text="@string/register" android:textColor="@color/main_tab_title_select" android:textSize="@dimen/big_seven" /> <TextView android:id="@+id/PasswordLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="@dimen/dp_30" android:text="@string/password_login" android:textColor="@color/login_view_" android:textSize="@dimen/small" android:visibility="visible" /> <TextView android:id="@+id/codeLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="@dimen/dp_30" android:text="@string/verificationCodeLogin" android:textColor="@color/login_view_" android:textSize="@dimen/small" android:visibility="gone" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="@dimen/dp_15" android:gravity="center" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我已阅读并同意" android:textColor="@color/title_fans" android:textSize="@dimen/micro" tools:ignore="HardcodedText" /> <TextView android:id="@+id/userPolicy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/user_policy" android:textColor="@color/main_tab_title_select" android:textSize="@dimen/micro" tools:ignore="HardcodedText" /> <TextView android:id="@+id/tv_private_protocol" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/privacy_agreement" android:textColor="@color/main_tab_title_select" android:textSize="@dimen/micro" tools:ignore="HardcodedText" /> </LinearLayout> </RelativeLayout> </ScrollView>
Android 软件盘弹出时把顶部局顶上去的解决方法
最新推荐文章于 2021-05-28 06:46:47 发布