单击时,键盘会阻止EditText

时间:2013-02-10 17:09:47

标签: android android-layout

问题标题可能会产生误导,但我认为我认为这是Android新手的常见问题:我有LinearLayout的活动,而我的底部有一个EditText屏幕。当我点击它时,键盘出现在EditText上方,在键入时隐藏它。有没有办法实现大多数用户的期望,即活动是否向下滚动,直到EditText再次可见?

6 个答案:

答案 0 :(得分:1)

您可以使用ScrollView来实现此目的。

答案 1 :(得分:1)

您可以使用ScrollView作为顶视图。并在其中定义RelativeLayout

一样定义
<Scrollview.......>
   <RelativeLayout .....>
         //other view.
   </RelativeLayout >
</Scrollview>

答案 2 :(得分:1)

LinearLayout的内容添加到Scrollview,当EditText视图集中时,manually scroll ScrollView。 多数民众赞成。

答案 3 :(得分:0)

您是否尝试将android:windowSoftInputMode="stateVisible|adjustResize"添加到清单中的活动中?

答案 4 :(得分:0)

如果adjustResize仍无法完全显示您想要的视图,则可以尝试此操作。无论您关注什么视图制作onTouchListener然后执行此操作:

    setOnTouchListener(new OnTouchListener()  {



        Runnable shifter=new Runnable(){
            public void run(){
                try {
                    int[] loc = new int[2];                 
                    //get the location of someview which gets stored in loc array
                    findViewById(R.id.someview).getLocationInWindow(loc);
                    //shift so user can see someview
                    myscrollView.scrollTo(loc[0], loc[1]);   
                }
                catch (Exception e) {
                    e.printStackTrace();
                }   
            }}
        };

        Rect scrollBounds = new Rect();
        View divider=findViewById(R.id.someview);
        myscollView.getHitRect(scrollBounds);
        if (!divider.getLocalVisibleRect(scrollBounds))  {
            // the divider view is NOT  within the visible scroll window thus we need to scroll a bit.
            myscollView.postDelayed(shifter, 500);
        }



    });

//基本上我们制作一个可运行的滚动到某个视图的新位置,你想在屏幕上看到它。只有当它不在scrollviews范围内(它不在屏幕上)时才执行该runnable。这样它就会将scrollview转换为引用的视图(在我的情况下,'someview'是一个行分隔符)。

答案 5 :(得分:0)

最简单的方法是将android:windowSoftInputMode="adjustPan"添加到清单上的目标活动中。