Keyboard Placement Obscures View Below Edittext Would Like To Keep Visible
Solution 1:
Vishavjeet got me on the right track in suggesting I scrolldown to reveal the view that may be overlapped by the keyboard. Below is a function similar to what I used to solve the problem. It can be called when the EditText above the TextView receives focus:
// View targetView; // View that may be hidden by keyboard// ScrollView scrollContainerView; // Scrollview containing hiddenView//voidassureViewVisible(View targetView, ScrollView, scrollContainerView) {
WindowrootWindow= activity.getWindow();
RectrMyView=newRect();
Viewrootview= rootWindow.getDecorView();
rootview.getWindowVisibleDisplayFrame(rMyView); // Area not taken up by keyboardint subTextPos[] = newint[2];
targetView.getLocationInWindow(subTextPos); // Get position of targetViewintsubTextHt= targetView.getHeight(); // Get bottom of target viewif ((subTextPos[1]+subTextHt) > rMyView.bottom) { // Is targetView at all obscured?intscrollBy= (subTextPos[1]+subTextHt) - rMyView.bottom + 10; // add a small bottom margin
mMeasurementViewScrollView.smoothScrollBy(0, scrollBy); // Scroll to subtext
}
}
Solution 2:
EDIT: By understanding the problem more deeply, I think that you should add scroll programatically when user clicks on the Edittext. Here is the code to do that:
private final voidfocusOnView()
{
newHandler().post(newRunnable()
{
@Overridepublicvoidrun()
{
your_scrollview.scrollTo(0, your_EditBox.getBottom());
}});
}
From my personal experience I think there is not such way to do that. The thing you can do is place the hint textview toRightOf the editext. Or Use modern Approach by using a Hint Placeholder on Edittext:
In XML, it's simply android:hint="someText"
Programatically you can use edittext.setHint(int);
pass R.string.somestring in above method.
Post a Comment for "Keyboard Placement Obscures View Below Edittext Would Like To Keep Visible"