为什么 windowSoftInputMode 不适用于约束布局?
这更像是我问的一般信息问题我尝试在约束布局中实现 windowSoftinputMode="adjustResize" 模式,但它根本不起作用我尝试搜索约束布局示例,但没有可用的示例在互联网上。我能找到的唯一示例是相对布局,当我实现它时,它就像一个魅力,所以请告诉我为什么它会这样工作
这是我的约束布局代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/fromtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:fontFamily="@font/nunito_sans_semibold"
android:text="@string/from"
android:textSize="@dimen/_15sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="@+id/fromSpinner"
android:layout_width="match_parent"
android:layout_height="@dimen/_35sdp"
android:layout_marginHorizontal="@dimen/_20sdp"
android:entries="@array/weight"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/fromtext"
app:layout_constraintVertical_bias="0.085" />
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_15sdp"
android:id="@+id/fromvalue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/fromSpinner"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="13dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:textAlignment="center"
android:textSize="@dimen/_15sdp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/totext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_50sdp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_gravity="center"
android:text="@string/to"
app:layout_constraintTop_toBottomOf="@+id/fromvalue"
android:textSize="@dimen/_20sdp"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="@dimen/_35sdp"
android:layout_margin="@dimen/_15sdp"
android:entries="@array/weight"
app:layout_constraintTop_toBottomOf="@+id/totext"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:textAlignment="center"
android:id="@+id/toSpinner"/>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/toSpinner"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_margin="@dimen/_15sdp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tovalue"
android:layout_width="match_parent"
android:focusable="false"
android:textSize="@dimen/_20sdp"
android:textAlignment="center"
android:cursorVisible="false"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
更新 现在我的应用程序的行为像这样 当键盘隐藏时
键盘未隐藏时
我希望我的屏幕完全调整大小,而不仅仅是一个元素
This is more like the general information question that I am asking I tried to implement windowSoftinputMode="adjustResize" mode in constraint layout but it doesn't work for it at all I tried to search for a constraint layout example but there is no example available on the internet. The only example I am able to find is with relative layout and when I implemented it worked like a charm so please tell me why it works like that
here is my constraint layout code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/fromtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:fontFamily="@font/nunito_sans_semibold"
android:text="@string/from"
android:textSize="@dimen/_15sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="@+id/fromSpinner"
android:layout_width="match_parent"
android:layout_height="@dimen/_35sdp"
android:layout_marginHorizontal="@dimen/_20sdp"
android:entries="@array/weight"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/fromtext"
app:layout_constraintVertical_bias="0.085" />
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_15sdp"
android:id="@+id/fromvalue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/fromSpinner"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="13dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:textAlignment="center"
android:textSize="@dimen/_15sdp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/totext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_50sdp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_gravity="center"
android:text="@string/to"
app:layout_constraintTop_toBottomOf="@+id/fromvalue"
android:textSize="@dimen/_20sdp"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="@dimen/_35sdp"
android:layout_margin="@dimen/_15sdp"
android:entries="@array/weight"
app:layout_constraintTop_toBottomOf="@+id/totext"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:textAlignment="center"
android:id="@+id/toSpinner"/>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/toSpinner"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_margin="@dimen/_15sdp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tovalue"
android:layout_width="match_parent"
android:focusable="false"
android:textSize="@dimen/_20sdp"
android:textAlignment="center"
android:cursorVisible="false"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
update
Now my app behaves like this
when the keyboard is hidden
when the keyboard is not hidden
i want my screen to be fully resized not just one element
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论