我想实现一些功能,例如每当我打开软键盘时,我的整个布局就会在android键盘上方。我已经在google上找到了一些合适的答案。但这没有达到我的预期。
我已在清单中添加了此代码:android:windowSoftInputMode =“ adjustResize”。但是它只能在键盘上方进行有限的布局。我希望我的整个布局都在键盘上方。
下面是一些可以更好地表示的图像...
如您在图像中所见,我的键盘位于布局上方。我希望我的整个布局意味着直到“注册”按钮位于软键盘上方。
下面是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Welcome,"
android:textAlignment="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register to Get Your Grocery Store Online"
android:textAlignment="center"
/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/storeName"
style="@style/TextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewLabel"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Store Name"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/storeLocationPinCode"
style="@style/TextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewLabel"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Store Location PinCode"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/storeCity"
style="@style/TextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewLabel"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Store City"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/storeState"
style="@style/TextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewLabel"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Store State"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/storeAddress"
style="@style/TextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewLabel"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Store Address"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/minimumAmount"
style="@style/TextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewLabel"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/deliveryCharges"
style="@style/TextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewLabel"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Delivery Charges"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/registerMerchant"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Register"
android:layout_marginTop="65dp"
android:layout_marginBottom="65dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
答案 0 :(得分:1)
对于您而言,我认为adjustPan
比adjustResize
更好,它将提高您的所有布局。
adjustResize
取决于布局参数,如果您使用的是ConstraintLayout
,则仅将约束从下到上的视图向上推。
<activity android:windowSoftInputMode="adjustPan"/>
答案 1 :(得分:0)
尝试添加
<activity android:windowSoftInputMode="adjustResize"/>
转到清单文件中的活动