2016-03-07 69 views
0

第一次点击expandablelistview中的edittext,整个布局滚动,用户可以看到edittext。然后点击软键盘完成折叠软键盘并再次点击此编辑文本,软键盘显示,但整个布局不滚动,用户无法看到编辑文本。我也在listview中找到了这个。我搜索了很长时间,有人说这是一个恶意程序错误? 有没有更换?adjustpan无法在expandablelistview中点击第二次同一编辑文字时

回答

0

花了很多天,我找到了解决方案。这是一个黑客。

  1. 把你edittext包裹在linearlayout中。
  2. 通过可见的布局更改来检测软键盘显示。

    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. 当softkeyboard节目,拿起ListView项或expandablelistview子项目一个TextView。然后为任何事物设置文本,整个视图像正常一样滚动!这样的代码:

    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. 这个TextView的显示隐身可为用户正确purpose.if这是一个expandablelistview和childitem中的EditText,TextView的更新必须在childitem。

0

我也遇到了同样的问题,但在google搜索了一段时间之后,我最终发现问题如下。

1)添加机器人:windowSoftInputMode = “adjustPan” 标签内的活动清单文件

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

2)添加机器人:descendantFocusability = “beforeDescendants” 属性的列表视图可扩展如下。

<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" /> 
+0

没有这个不行,点击这个edittext第二次,softkeyboard显示,但是整个布局没有滚动,而且用户看不到edittext。你做得好吗? – byedo

相关问题