android中网格布局组件溢出原因

问题描述:这是一个简单的网格布局应用,计算器界面,代码如下:


< GridLayout xmlns: android = "http://schemas.android.com/apk/res/android"xmlns: tools = "http://schemas.android.com/tools"android :layout_width= "match_parent"android :layout_height= "match_parent"android :rowCount= "6"android :columnCount= "4"tools :context= "com.lifei.helloworld.TestGrid">< TextViewandroid:id= "@+id/t1"android:layout_width= "match_parent"android:layout_height= "wrap_content"android:textSize= "50sp"android:padding= "3pt"android:background= "#eee"android:textColor= "#000"android:text= "0" />

图形界面如下,可以看到,按钮一还在,但是其余的按钮在外面:
原因分析:能让按钮1占一行的可能原因是,该列的宽度由该列中最宽的组件决定, 而按钮1所在的第0列,还包含上面一个TextView和一个“清除按钮”, 所以, ①在TextView中补一句: android:layout_columnSpan= "4",那么第0列 TextView变成了占4列的TextView了 ②如果你连“1”号按钮也占一行,请把相应属性改 为:                   android:layout_width= "wrap_content"
        


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部