我知道这个问题在互联网上已经存在很久了,但对我来说似乎没有任何效果。
怎么了
如屏幕截图所示,具有微调器的布局未向上推,而是与软键盘重叠。我希望此布局在弹出时正好位于键盘上方。
我的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="@android:color/white"
android:orientation="vertical"
tools:context="believe.cht.speak.MainActivity">
<ImageView
android:id="@+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="@drawable/ic_bubble"
android:tint="@color/blue" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />
<ImageView
android:id="@+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="@drawable/shadow" />
<RelativeLayout
android:id="@+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/blue">
<Spinner
android:id="@+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
我尝试过的
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan" //in the manifest, also tried combining the two
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //in the activity
<item name="android:windowActionBarOverlay">true</item> //in styles.xml
最佳答案
试试这个
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<ImageView
android:id="@+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="@drawable/ic_message" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />
<ImageView
android:id="@+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="@drawable/ic_camera" />
<RelativeLayout
android:id="@+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary">
<Spinner
android:id="@+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
list 文件
<activity android:name=".MyActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
输出
关于java - 修复软键盘上方的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50987381/