2013-05-15 77 views
4

我想滾動我的佈局softinput鍵盤可見時。我已經在我的xml在適當的地方定義滾動視圖,但當鍵盤可見時,它隱藏了一些佈局的一部分鈕釦。 我已閱讀stackoveflow Link scrollview不工作時,活動是FULL_SCREEN.If它是真的,那麼我怎麼可以滾動我的佈局時softinput可見。如何滾動佈局當鍵盤可見在活動與FULL_SCREEN

+0

告訴我們你的代碼PLZ –

+0

<滾動型機器人:ID = 「@ + ID/scrol」 機器人:layout_width = 「FILL_PARENT」 機器人:layout_height = 「FILL_PARENT」> <的EditText機器人:ID = 「@ + ID /測試」 機器人:layout_width = 「FILL_PARENT」 機器人:layout_height = 「WRAP_CONTENT」 /> <的EditText機器人:ID =「@ + id/test1「 android:layout_width =」fill_parent「 android:layout_height =」wrap_content「 android:layout_below =」@ id/test「 />

+0

可能會有助於http://stackoverflow.com/questions/11298479/can-not-get-scrollview-to-scroll-when-soft-keyboard-is-shown使您的滾動視圖父母 –

回答

1

使用此自定義相對佈局在烏爾XML檢測softkeyboard與

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 mainLayout = (RelativeLayoutThatDetectsSoftKeyboard)V.findViewById(R.id.dealerSearchView); 
    mainLayout.setListener(this); 




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


    } else { 

    } 
} 

實現RelativeLayoutThatDetectsSoftKeyboard.Listener您活性研究班能見度將佈局上下移動使用佈局參數