ソフト入力キーボードが表示されているときにレイアウトを上にスクロールしたい.xmlの適切な場所でスクロールビューを定義していますが、キーボードが表示されていると、ボタンのようなレイアウトの一部が非表示になります。アクティビティがFULL_SCREENの場合、スクロールビューが機能しないことをstackoveflowリンクで読みました.trueの場合、softinputが表示されているときにレイアウトをスクロールアップするにはどうすればよいですか。
4188 次
2 に答える
1
このカスタム相対レイアウトを使用して、ur xml でソフトキーボードを検出します
import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
/**
* RelativeLayout that can detect when the soft keyboard is shown and hidden.
*
*/
public class RelativeLayoutThatDetectsSoftKeyboard extends RelativeLayout {
public RelativeLayoutThatDetectsSoftKeyboard(Context context, AttributeSet attrs) {
super(context, attrs);
}
public interface Listener {
public void onSoftKeyboardShown(boolean isShowing);
}
private Listener listener;
public void setListener(Listener listener) {
this.listener = listener;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = MeasureSpec.getSize(heightMeasureSpec);
Activity activity = (Activity)getContext();
Rect rect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight();
int diff = (screenHeight - statusBarHeight) - height;
if (listener != null) {
listener.onSoftKeyboardShown(diff>128); // assume all soft keyboards are at least 128 pixels high
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
次に、 RelativeLayoutThatDetectsSoftKeyboard.Listener を Activity クラスに実装します
RelativeLayoutThatDetectsSoftKeyboard mainLayout = (RelativeLayoutThatDetectsSoftKeyboard)V.findViewById(R.id.dealerSearchView);
mainLayout.setListener(this);
@Override
public void onSoftKeyboardShown(boolean isShowing) {
if(isShowing) {
} else {
}
}
キーボードの可視性に基づいて、レイアウト パラメータを使用してレイアウトを上下に移動します
于 2013-05-15T09:41:44.653 に答える
0
マニフェスト ファイルを変更する必要があります
あなたのアクティビティタグに
android:windowSoftInputMode="adjustPan" これを追加します。
これを参照してくださいhttp://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
于 2013-05-15T09:15:27.000 に答える