Ich weiß nicht, wie Sie OnGlobalLayoutListener
verwenden, aber es funktioniert unten in meinem Code fein:
final View activityRootView = findViewById(R.id.container);
final ViewTreeObserver observer = activityRootView
.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
// r will be populated with the coordinates of your view
// that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight()
- (r.bottom - r.top);
Toast.makeText(TestActivity.this, String.valueOf(heightDiff),
Toast.LENGTH_SHORT).show();
}
});
Der obige Code ist in onResume()
meiner TestActivity mit dem Thema @android:style/Theme.NoTitleBar.Fullscreen
Layout-Datei für die Ausblick:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="aaa" />
</LinearLayout>
Die Aktivität config in menifest:
<activity
android:name=".ui.activity.TestActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Kannst du die XML auch posten, meine Anwendung hat nur eine Aktivität und alles andere sind Fragmente. – Niko
http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-isvisible Dies besagt eindeutig, dass es nicht funktioniert und Es gibt auch Bugs für Google darüber. – Niko
Und aufgrund dieser Post scheint das ein Duplikat zu sein. – Niko