Android 页脚布局显示在键盘上方
我的布局在底部有一个webview和一个页脚布局 在webview内的任何字段中输入文本时,页脚布局显示在键盘顶部。我尝试在清单文件中设置android:WindowsOfInputMode=“somevalue”。我删除了android:layou-weight参数,并对高度进行了硬编码。在这两种情况下,它都可以正常工作,并且页脚不会显示在键盘上,但会导致另一个问题,即键盘现在在webview的编辑字段上重叠。在应用这些修复之前,当键盘变得可见时,字段会自动向上滚动 如何确保页脚布局保持在底部,并在键盘显示时向上滚动编辑字段Android 页脚布局显示在键盘上方,android,android-webview,Android,Android Webview,我的布局在底部有一个webview和一个页脚布局 在webview内的任何字段中输入文本时,页脚布局显示在键盘顶部。我尝试在清单文件中设置android:WindowsOfInputMode=“somevalue”。我删除了android:layou-weight参数,并对高度进行了硬编码。在这两种情况下,它都可以正常工作,并且页脚不会显示在键盘上,但会导致另一个问题,即键盘现在在webview的编辑字段上重叠。在应用这些修复之前,当键盘变得可见时,字段会自动向上滚动 如何确保页脚布局保持在底部
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".feature.webview.WebViewActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
android:background="@color/colorPrimary"
android:clickable="true"
android:paddingLeft="@dimen/dp_14"
android:paddingRight="@dimen/dp_14">
<ImageView
android:id="@+id/img_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:contentDescription="@string/defaultContentDescription"
android:padding="@dimen/dp_14"
android:src="@drawable/icn_back"
android:visibility="gone" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@string/defaultContentDescription"
android:src="@drawable/icn_hundred_for_good" />
<ImageView
android:id="@+id/img_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="@string/defaultContentDescription"
android:padding="@dimen/dp_5"
android:src="@drawable/icn_profile"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dp_14"
android:background="@color/white">
</View>
<RelativeLayout
android:id="@+id/rl_footer"
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
android:background="@color/colorPrimary"
android:paddingLeft="@dimen/dp_60"
android:paddingRight="@dimen/dp_60"
android:visibility="gone">
<LinearLayout
android:id="@+id/layout_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/img_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/defaultContentDescription"
android:src="@drawable/icn_home" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/source_sans_pro_regular"
android:lineSpacingMultiplier="1.20"
android:paddingTop="@dimen/dp_3"
android:text="@string/home"
android:textColor="@color/white"
android:textSize="@dimen/sp_10" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_record_act"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical"
android:paddingEnd="@dimen/dp_3">
<ImageView
android:id="@+id/img_record_act"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/defaultContentDescription"
android:src="@drawable/icn_setting" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/source_sans_pro_regular"
android:lineSpacingMultiplier="1.20"
android:paddingTop="@dimen/dp_3"
android:text="@string/record_act"
android:textColor="@color/white"
android:textSize="@dimen/sp_10" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_dashboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/img_dashboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/defaultContentDescription"
android:src="@drawable/icn_dashboard" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/source_sans_pro_regular"
android:lineSpacingMultiplier="1.20"
android:paddingTop="@dimen/dp_3"
android:text="@string/dashboard"
android:textColor="@color/white"
android:textSize="@dimen/sp_10" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
我认为这会奏效。
在此relativeLayoutScreen中是父主布局。
和relativeLayoutFooter是页脚布局名称
这是经过测试的代码,正在运行。发送xml的完整代码更新完整的xml代码@007尝试过,但不起作用。如果我在清单中添加“android:windowSoftInputMode=“adjustPan”,页脚仍然会出现在键盘上,但正如我所说,编辑字段的自动滚动会停止,编辑字段上的键盘会重叠。请检查答案这现在工作正常@abhishekmaharajpetThanks,这工作!!但我觉得这更像是一种黑客行为。在“onGlobalLayout()”中多次抛出回调。我也看到了一些闪烁的问题。我现在将坚持这个解决方案。如果仅仅通过更改布局结构和清单属性就可以解决这个问题,我将继续挖掘。再次感谢。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/rl_footer" />
<RelativeLayout
android:id="@+id/rl_footer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:visibility="visible">
<ImageView
android:id="@+id/img_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<ImageView
android:id="@+id/img_record_act"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ImageView
android:id="@+id/img_dashboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true" />
</RelativeLayout>
</RelativeLayout>
relativeLayoutScreen.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = relativeLayoutScreen.getRootView().getHeight() - relativeLayoutScreen.getHeight();
if (heightDiff > 100) {
Log.e("MyActivity", "keyboard opened");
relativeLayoutFooter.setVisibility(View.GONE);
} else {
Log.e("MyActivity", "keyboard closed");
relativeLayoutFooter.setVisibility(View.VISIBLE);
}
}
});