gpt4 book ai didi

java - 如何防止键盘打开时底部 View 向上推

转载 作者:行者123 更新时间:2023-12-02 08:59:21 24 4
gpt4 key购买 nike

屏幕上有两个编辑文本,屏幕底部有一个按钮,问题是当我单击编辑文本并且键盘打开时,底部的按钮出现在键盘上方,我希望底部按钮位于其原始位置放置而不是用键盘向上移动。按钮底部对齐

谢谢

附:我尝试过调整平移、调整大小等,但没有任何效果

<activity
android:screenOrientation="portrait"
android:name=".activities.MainActivity"
android:windowSoftInputMode="stateUnchanged|adjustResize"
android:theme="@style/AppTheme"
/>

XML:

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/text_white"
android:orientation="vertical"
android:paddingTop="@dimen/_20sdp"
android:elevation="5dp"
tools:context=".fragments.login.LoginFragment">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_welcome"
android:layout_marginRight="@dimen/_40sdp"
android:layout_marginStart="@dimen/_20sdp"
app:layout_constraintLeft_toLeftOf="parent"
android:maxLines="2"
style="@style/headingText"
android:text="Welcome to the World \nof PACKR" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:id="@+id/tv_continue"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/tv_welcome"
android:layout_marginTop="10dp"
android:layout_marginEnd="@dimen/_20sdp"
android:layout_marginStart="@dimen/_20sdp"
app:layout_constraintLeft_toLeftOf="parent"
android:text="Sign in to continue" />

<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="@dimen/_20sdp"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_marginStart="@dimen/_20sdp"
android:layout_marginEnd="@dimen/_20sdp"
app:layout_constraintTop_toBottomOf="@+id/tv_continue"
android:id="@+id/phone_layout"
android:orientation="horizontal">

<com.hbb20.CountryCodePicker
android:layout_marginEnd="@dimen/_10sdp"
android:layout_width="0dp"
android:layout_weight="0.4"
android:textSize="@dimen/_12sdp"
android:id="@+id/countryCode"
style="@style/smallText"
android:background="@drawable/edittext_background"
android:layout_height="match_parent" />

<EditText
android:layout_width="0dp"
android:layout_weight="0.6"
android:hint="Phone Number"
android:inputType="number"
style="@style/smallText"
android:id="@+id/et_phone"
android:maxLength="11"
android:padding="@dimen/_10sdp"
android:drawablePadding="10dp"
android:drawableStart="@drawable/ic_phone"
android:background="@drawable/edittext_background"
android:layout_height="wrap_content" />
</LinearLayout>


<EditText
android:layout_width="match_parent"
android:layout_marginTop="@dimen/_10sdp"
android:hint="Password"
android:singleLine="true"
android:drawablePadding="10dp"
android:layout_marginEnd="@dimen/_20sdp"
android:layout_marginStart="@dimen/_20sdp"
app:layout_constraintTop_toBottomOf="@+id/phone_layout"
app:layout_constraintLeft_toLeftOf="parent"
android:padding="@dimen/_10sdp"
style="@style/smallText"
android:inputType="textPassword"
android:id="@+id/et_password"
android:drawableStart="@drawable/ic_lock"
android:background="@drawable/edittext_background"
android:layout_height="wrap_content" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:id="@+id/forgot_layout"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="@dimen/_15sdp"
android:layout_height="wrap_content">


<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="@+id/forgot_pass"
app:layout_constraintLeft_toLeftOf="@+id/forgot_pass"
android:src="@drawable/forgot_icon"
android:layout_marginEnd="@dimen/_20sdp"
android:layout_marginStart="@dimen/_20sdp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
style="@style/smallText"
android:layout_marginEnd="@dimen/_20sdp"
android:layout_marginStart="@dimen/_20sdp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img_"
android:layout_gravity="right"
android:padding="@dimen/_5sdp"
android:textColor="@color/grey_border"
android:id="@+id/forgot_pass"
android:layout_marginTop="8dp" />
</androidx.constraintlayout.widget.ConstraintLayout>


<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn_signin"
android:textAppearance="@style/textOnButton"
android:text="Login"
app:layout_constraintTop_toBottomOf="@+id/et_password"
android:layout_marginEnd="@dimen/_20sdp"
android:layout_marginStart="@dimen/_20sdp"
android:layout_marginTop="@dimen/_30sdp"
android:paddingLeft="5dp"
/>


<ProgressBar
android:id="@+id/pb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:minWidth="50dp"
android:gravity="center"
android:indeterminate="true"
android:elevation="10dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="@color/orange"
/>



</androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

更新 list 中 Activity 标记中的以下内容:

android:windowSoftInputMode="adjustNothing"

关于java - 如何防止键盘打开时底部 View 向上推,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60282152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com