![](/img/trans.png)
[英]Android windowSoftInputMode=“adjustPan” scroll some more
[英]How to scroll my layout when setting android:windowSoftInputMode=“adjustPan”?
我的活動有一個頂欄和一個底欄。 topbar和bottom bar之間的空間我有一個linearlayout,里面有幾個edittext視圖。 因為我不希望每次軟鍵盤出現時我的布局都會調整大小,所以我為manifest中的活動設置了android:windowSoftInputMode =“adjustPan”。 但是當打開軟鍵盤時,我想向下滾動以選擇另一個要輸入的編輯文本,這是不允許我這樣做的。 我只能在關閉軟鍵盤時選擇底部的edittext。 這非常煩人且不方便。 如何才能同時獲得軟鍵盤的scrollview和ajustpan模式?
請幫幫我。 非常感謝。
最后,我找到了我的問題的解決方法,所以我想分享給某人可能會在將來遇到同樣的問題。 我的布局簡要描述如下:
<myRelativeLayout>
<topbar.../>
<myscrollView>
<linearLayout>
//all stuff controls:editview,textview,....
</linearLayout>
</myscrollView>
<bottombar.../>
我創建自定義類myRelativeLayout擴展RelativeLayout
public class myRelativeLayout extends RelativeLayout{
public interface OnRelativeLayoutChangeListener {
void onLayoutPushUp();
void onLayoutPushDown();
}
private OnRelativeLayoutChangeListener layoutChangeListener;
public myRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
final int actualHeight = getHeight();
if (actualHeight > proposedheight){
// Keyboard is shown
layoutChangeListener.onLayoutPushUp();
} else if(actualHeight < proposedheight){
// Keyboard is hidden
layoutChangeListener.onLayoutPushDown();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public void setLayoutChangeListener(OnRelativeLayoutChangeListener layoutChangeListener) {
this.layoutChangeListener = layoutChangeListener;
}
public OnRelativeLayoutChangeListener getLayoutChangeListener() {
return layoutChangeListener;
}
}
在我的活動中,我只是為myRelativeLayout設置setLayoutChangeListener以在軟鍵盤顯示時隱藏底欄並在軟鍵盤隱藏時顯示底欄:
myRlayout.setLayoutChangeListener(new OnRelativeLayoutChangeListener() {
@Override
public void onLayoutPushUp() {
// TODO Auto-generated method stub
myBottombar.setVisibility(View.GONE);//in my case i need to setVisibility(View.GONE) to bottombar in order for this bar is not displayed when softkeyboard show up.
}
@Override
public void onLayoutPushDown() {
// TODO Auto-generated method stub
myBottombar.setVisibility(View.VISIBLE);// redisplay myBottombar when keyboard is closed.
}
});
不要忘記為活動設置android:windowSoftInputMode =“adjustResize”。 希望這對有人遇到同樣問題很有用。
將這些EditText
放在ScrollView
如下所示:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.