当键盘出现时我的页脚出现
My footer comes up when keyboard appears
我用一些按钮制作了一个简单的页脚,它显示得很好,但我只有 1 个问题,当键盘为 visible
时它不应该出现。它应该保持向下并且键盘必须覆盖它。
这是我的布局文件-
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView2"
android:layout_above="@id/footerView">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="@+id/textView40"
android:layout_weight="2"
android:paddingLeft="30dp"
android:textAlignment="gravity"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/ETNameSU"
android:hint="Daksh Agrawal"
android:layout_weight="1"
android:layout_marginRight="30dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/footerView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/view_books"
android:layout_weight="1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:layout_weight="1"
android:src="@drawable/my_profile" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView3"
android:layout_weight="1"
android:src="@drawable/post_book" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:layout_weight="1"
android:src="@drawable/chat" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView5"
android:layout_weight="1"
android:src="@drawable/top_donors" />
</LinearLayout>
删除android:layout_above="@id/footerView"
祈祷让我们自定义它-(经过测试,对我来说效果很好!)
在您的 OnCreate
中初始化您的 rootView
(您的 XML 中的父视图)和您的 footerView
从您的 OnCreate
调用此方法- 一旦键盘启动 footerView
可见性改变
public void testKeyBoardUp(){
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int heightDiff = rel.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
//ok now we know the keyboard is up...
footer.setVisibility(View.INVISIBLE);
}else{
//ok now we know the keyboard is down...
footer.setVisibility(View.VISIBLE);
}
}
});
}
希望你喜欢
将此添加到您的清单中 activity
android:windowSoftInputMode="hidden"
我用一些按钮制作了一个简单的页脚,它显示得很好,但我只有 1 个问题,当键盘为 visible
时它不应该出现。它应该保持向下并且键盘必须覆盖它。
这是我的布局文件-
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView2"
android:layout_above="@id/footerView">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="@+id/textView40"
android:layout_weight="2"
android:paddingLeft="30dp"
android:textAlignment="gravity"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/ETNameSU"
android:hint="Daksh Agrawal"
android:layout_weight="1"
android:layout_marginRight="30dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/footerView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/view_books"
android:layout_weight="1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:layout_weight="1"
android:src="@drawable/my_profile" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView3"
android:layout_weight="1"
android:src="@drawable/post_book" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:layout_weight="1"
android:src="@drawable/chat" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView5"
android:layout_weight="1"
android:src="@drawable/top_donors" />
</LinearLayout>
删除android:layout_above="@id/footerView"
祈祷让我们自定义它-(经过测试,对我来说效果很好!)
在您的 OnCreate
中初始化您的 rootView
(您的 XML 中的父视图)和您的 footerView
从您的 OnCreate
调用此方法- 一旦键盘启动 footerView
可见性改变
public void testKeyBoardUp(){
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int heightDiff = rel.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
//ok now we know the keyboard is up...
footer.setVisibility(View.INVISIBLE);
}else{
//ok now we know the keyboard is down...
footer.setVisibility(View.VISIBLE);
}
}
});
}
希望你喜欢
将此添加到您的清单中 activity
android:windowSoftInputMode="hidden"