adjustpan not work in expandablelistview when click second time for the same edittext

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

first time,click an edittext in expandablelistview,the whole layout scrolled ,and user can see edittext. then click softkeyboard finish to collapse softkeyboard and click this edittext second time ,softkeyboard show, but the whole layout not scrolled, and user cannot see edittext. I find this in listview ,too.I searched for a long time and some one says it is an anroid bug? Is there any replacement?

回答1:

By many days spent,I found a solution. It is a hack.

  1. put you edittext wrapped in linearlayout.
  2. detect softkeyboard show by visiable layout change.

     public final void setKeyboardListener(final OnKeyboardVisibilityListener listener) {   final View activityRootView = getWindow().getDecorView()     .findViewById(android.R.id.content);      activityRootView.getViewTreeObserver()     .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {        private final Rect r = new Rect();       private boolean wasOpened;        @Override       public void onGlobalLayout() {         activityRootView.getWindowVisibleDisplayFrame(r);          int heightDiff = activityRootView.getRootView().getHeight()             - (r.bottom - r.top);         boolean isOpen = heightDiff > 100;          if (isOpen == wasOpened) {           return;         }          wasOpened = isOpen;         listener.onVisibilityChanged(isOpen);       }     });    }    public interface OnKeyboardVisibilityListener {     void onVisibilityChanged(boolean visible);     }
  3. when the softkeyboard show,pick up a textview in listview item or expandablelistview child item. then set it text for any thing, the whole view scrolled as normal! code like this:

    activity.setKeyboardListener(new OnKeyboardVisibilityListener() {   @Override public void onVisibilityChanged(boolean visible) { if (visible) {   Message message = new Message();   message.what = 999;   handler.sendMessage(message);   }  } }); private Handler handler = new Handler() {  @Override public void handleMessage(Message msg) { if (msg.what == 999) {   if (mDataMap.size() > 0) {   for (int i = 0; i < expandablelistview.getChildCount(); i++) {     View v = expandablelistview.getChildAt(i);     TextView tvCannotSee = (TextView) v.findViewById(R.id.tv_cannot_see );     if (tvCannotSee != null) {       //this is the key hack to make adjuspan work! and scroll the whole view up as normal       tvCannotSee.setText("this is an android bug");       return;       }     }    }    return;   }  super.handleMessage(msg);  } };
  4. this textview show invisble to user for proper purpose.if it is a expandablelistview and the edittext in childitem,the textview update must be in a childitem.



回答2:

I also faced the same issue, but after googling the issue for some time i ended up the problem as below.

1) Add android:windowSoftInputMode="adjustPan" tag inside activity of manifest file

    <activity         android:name=".MainActivity"         android:configChanges="locale|keyboardHidden|orientation|screenSize|layoutDirection|screenLayout"         android:screenOrientation="portrait"         android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"></activity>

2) add android:descendantFocusability="beforeDescendants" attribute to your expandable listview as below.

    <ExpandableListView                 android:id="@android:id/list"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_above="@+id/textDate"                 android:layout_below="@+id/relativeLayout2"                 android:descendantFocusability="beforeDescendants"                 android:layout_margin="@dimen/margin_meium"                 android:groupIndicator="@android:color/transparent" />


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!