簡體   English   中英

如何使用FULL_SCREEN在活動中顯示鍵盤時如何向上滾動布局

[英]how to scroll up layout when keyboard visible in activity with FULL_SCREEN

當softinput鍵盤可見時,我想向上滾動我的布局。我已經在我的xml中在適當的位置定義了scrollview,但是當鍵盤可見時,它隱藏了一些布局,如按鈕。 我已經閱讀了stackoveflow 鏈接 ,當活動為FULL_SCREEN時,scrollview不起作用。如果是真的,那么當softinput可見時如何向上滾動我的布局。

使用此自定義相對布局在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實現到您的Actiity類

   RelativeLayoutThatDetectsSoftKeyboard mainLayout =  (RelativeLayoutThatDetectsSoftKeyboard)V.findViewById(R.id.dealerSearchView);
   mainLayout.setListener(this);




    @Override
public void onSoftKeyboardShown(boolean isShowing) {
    if(isShowing) {


    } else {

    }
}

基於鍵盤可見性,使用布局參數向上和向下移動布局

你必須改變你的清單文件

在您的活動標簽中

android:windowSoftInputMode =“adjustPan”添加此項。

請參閱此http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM