Screen Scrolling Up When Clicking On Any Edittext
I have one screen with 4 EditText like menuName, DishName,Tag and Price. I need to set my tag Edittext at top(+56dip) on clicking on it. Right now it's working fine. When i clic
Solution 1:
Your code only checks for the heightDiff
being over 100 before you execute performScrollingUp()
and your comment indicates that would probably occur when a keyboard pops up. Well when you click on any editText field a keyboard would pop up...
The Fix:
Try changing your first block of code to this:
finalViewactivityRootView= findViewById(R.id.RelativeAdd);
EditTexttagEditText= findViewById(R.id.txtTags);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
newViewTreeObserver.OnGlobalLayoutListener() {
@OverridepublicvoidonGlobalLayout() {
intheightDiff= activityRootView.getRootView()
.getHeight() - activityRootView.getHeight();
Log.i("TEST",
"GLOBAL LAYOUT " + activityRootView.getHeight());
Log.i("TEST", "GLOBAL LAYOUT rel"+ relativeLayoutHeight);
if (heightDiff > 100 && tagEditText.isFocused()) { // if more than 100 pixels, its// probably a keyboard...
performScrollingUp();
Log.i("TEsT", "Keyboard visible");
} else {
Log.i("TEsT", "Keyboard not visible");
performScrollingDown();
txtDishTags.setDropDownHeight(ViewGroup.LayoutParams.FILL_PARENT);
}
}
});
This will make sure that it only scrolls up when the tagEditText was the one clicked and not the others. Right now you are just listening for an overall layout change with your listener. Let me know if this works.
Solution 2:
In your AndroidManifest.xml that can solve this problem
<activityandroid:name="com.example.mainActivity"android:windowSoftInputMode="adjustPan"></activity>
Solution 3:
I'm not sure if this works. But I would at least do it like this:
if (heightDiff > 100) { // if more than 100 pixels, its// probably a keyboard...if(!isTagUp)
performScrollingUp();
Log.i("TEsT", "Keyboard visible");
isTagUp = true; // Keyboard is up
} else {
Log.i("TEsT", "Keyboard not visible");
if(isTagUp)
{
performScrollingDown();
txtDishTags.setDropDownHeight(ViewGroup.LayoutParams.FILL_PARENT);
}
isTagUp = false; // Keyboard is down again
}
This way the function doesn't even get called. Probably won't solve it, but give it a try..
Post a Comment for "Screen Scrolling Up When Clicking On Any Edittext"