Non so come lo si utilizza OnGlobalLayoutListener
ma funziona bene nel mio codice qui sotto:
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();
}
});
il codice di cui sopra è in onResume()
della mia TestActivity con il tema @android:style/Theme.NoTitleBar.Fullscreen
file di layout per la vista:
<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>
La configurazione attività 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>
Puoi anche postare l'xml, la mia applicazione ha solo un'attività e tutto il resto sono Frammenti. – Niko
http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible Questo afferma chiaramente che non funziona e ci sono anche bug per Google a riguardo. – Niko
E a causa di questo post sembra essere un duplicato. – Niko