0
這是我最頂層LL在我的XML爲什麼在軟鍵盤處於打開狀態時,heightDiff == 50?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue_bg"
android:gravity="center_horizontal"
android:orientation="vertical" >
然後我用這個代碼:
private void setKeyboardVisibilityListener()
{
final View root = findViewById(R.id.rootLayout);
root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// TODO Auto-generated method stub
View continueButton = findViewById(R.id.continueButton);
int heightDiff = root.getRootView().getHeight() - root.getHeight();
if (heightDiff > 100) { // more than 100 pixels is probably a keyboard
// keyboard is shown
mInputBox.setBackgroundResource(R.drawable.input_box_active);
} else {
// keyboard is not shown
mInputBox.setBackgroundResource(R.drawable.input_box_idle);
}
}
});
}
,但我總是得到heightDiff == 50
當軟鍵盤是,當它的出