私は、Samsung Galaxy Tab 3 用の phonegap アプリに取り組んでいます。このアプリケーションが全画面表示モードの場合、ソフトキーボードはテキスト入力フィールドを非表示にし、ページをスクロールしてコンテンツを表示することはできません。どうすれば問題を解決できますか?
6852 次
2 に答える
3
ホルヘの答えを実装しましたが、うまくいきました!. しかし、画面はかさばる方法でサイズを変更します。よりスムーズにサイズ変更したかったのです。そこで、このビューをアニメーション化する方法を調べたところ、これに出会いました。
2 つを組み合わせると、次のようになります。
import android.animation.ValueAnimator;
import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
public class AdjustInputHeight {
// For more information, see https://code.google.com/p/android/issues/detail?id=5497
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
public static void assistActivity (Activity activity) {
new AdjustInputHeight(activity);
}
private View mChildOfContent;
private int usableHeightPrevious;
private ValueAnimator animateCollapseView = null;
private ValueAnimator animateExpandView = null;
private boolean keyboardIsUp = false;
DecelerateInterpolator sDecelerator = new DecelerateInterpolator();
private FrameLayout.LayoutParams frameLayoutParams;
private AdjustInputHeight(Activity activity) {
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
//check if the view got smaller (because keyboard is shown) and is not already up.
if (heightDifference > (usableHeightSansKeyboard/4) && (!this.keyboardIsUp)) {
// we need to create the collapse animator the only the first time we rise the keyboard
if (this.animateCollapseView == null) {
this.animateCollapseView = ValueAnimator.ofInt(usableHeightSansKeyboard, (usableHeightSansKeyboard-heightDifference));
this.animateCollapseView.setDuration(500);
this.animateCollapseView.setInterpolator(sDecelerator);
this.animateCollapseView.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Integer value = (Integer) animation.getAnimatedValue();
frameLayoutParams.height = value.intValue();
mChildOfContent.requestLayout();
}
});
}
this.animateCollapseView.start();
// keyboard probably just became visible
this.keyboardIsUp = true;
//lower the keyboard only if it is up.
} else if (this.keyboardIsUp) {
// we need to create the expand animator the only the first time we lower the keyboard
if (this.animateExpandView == null) {
this.animateExpandView = ValueAnimator.ofInt((usableHeightSansKeyboard-heightDifference), usableHeightSansKeyboard);
this.animateExpandView.setDuration(200);
this.animateExpandView.setInterpolator(sDecelerator);
this.animateExpandView.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Integer value = (Integer) animation.getAnimatedValue();
frameLayoutParams.height = value.intValue();
mChildOfContent.requestLayout();
}
});
}
this.animateExpandView.start();
// keyboard probably just became hidden
this.keyboardIsUp = false;
}
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
}
}
もちろん、必要に応じてアニメーションの長さと補間を変更できます。
于 2014-01-06T14:23:31.447 に答える