android开发 Edittext编辑框超出屏幕

来源:互联网 发布:云天明 知乎 编辑:程序博客网 时间:2024/06/04 18:12

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


但是我的布局设置的是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" /> 

0 0
原创粉丝点击