您的位置:首页 > 移动开发 > Android开发

android开发 Edittext编辑框超出屏幕

2015-07-29 16:04 411 查看
今天导入一段别人写的计算器源码,运行后发现编辑框里的数字有一部分在屏幕外面,如下图所示:



但是我的布局设置的是match parent,无法理解为什么会出现这种情况。

<EditText android:id="@+id/result" 

            android:layout_width="match_parent" 

            android:layout_height="wrap_content" 

            android:background="@android:drawable/editbox_background" 

            android:layout_span="4" 

            android:textSize="48sp" 

            android:gravity="right|center_vertical" 

            android:cursorVisible="false" 

            android:editable="true" 

            android:lines="1"  /> 

后来我进入到Graphical layout中预览,发现也是这种情况,如下图所示:



后来将Api22调到Api17,发现Graphical layout中预览的编辑框终于不超出屏幕外了:


自此,我以为问题解决了。运行程序结果编辑框还是在屏幕外。百撕不得骑姐。。

后来尝试无数次,最后在加入layout_weight属性才终于解决问题,什么原因现在还不清楚。

        <EditText android:id="@+id/result" 

            android:layout_width="match_parent" 

            android:layout_height="wrap_content" 

            android:background="@android:drawable/editbox_background" 

            android:layout_span="4" 

            android:textSize="48sp" 

            android:gravity="right|center_vertical" 

            android:cursorVisible="false" 

            android:editable="true" 

            android:lines="1" 

            android:layout_weight="1" /> 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息