android中网格布局组件溢出原因
2016-10-08 20:13
225 查看
问题描述:这是一个简单的网格布局应用,计算器界面,代码如下:
<? xml version= "1.0" encoding= "utf-8" ?> < 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"> <!-- 定义一个横跨 4 列的文本框,并定义前景色和背景色等属性 --> < TextView android: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" /> <Button android:id= "@+id/clear" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_columnSpan= "4" android:text= " 清除 " /> <Button android:id= "@+id/c1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_column= "0" android:layout_row= "2" android:text= "1" /> <Button android:id= "@+id/c2" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_column= "1" android:layout_row= "2" android:text= "2" /> <Button android:id= "@+id/c3" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_column= "2" android:layout_row= "2" android:text= "3" /> <Button android:id= "@+id/c4" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_column= "3" android:layout_row= "2" android:text= "4" /> </GridLayout >图形界面如下,可以看到,按钮一还在,但是其余的按钮在外面: 原因分析:能让按钮1占一行的可能原因是,该列的宽度由该列中最宽的组件决定, 而按钮1所在的第0列,还包含上面一个TextView和一个“清除按钮”, 所以, ①在TextView中补一句:android:layout_columnSpan= "4",那么第0列 TextView变成了占4列的TextView了 ②如果你连“1”号按钮也占一行,请把相应属性改为: android:layout_width= "wrap_content"
相关文章推荐
- android中四大组件,五大布局
- Android组件----RelativeLayout相对布局的属性详解
- 几种Android布局layout组件主要常用属性
- Android零基础入门第32节:新推出的GridLayout网格布局
- Android一样的CoordinatorLayout布局却不一样的效果,找了一晚上的原因
- 第16章、布局Layouts之GridLayout网格布局(从零开始学Android)
- android 组件,xml布局中属性详解
- Android网格布局实现--GridView
- Android 组件布局
- 【android_温故知新】第 1 组 UI 组件:布局管理器
- Android网格布局tablerow中控件排列技巧
- android的四大组件、五大存储、六大布局、七大生命周期、八大基本数据类型
- Android之四大组件、六大布局、五大存储
- 【Android学习】 LinearLayout 组件左右分开的布局设置
- Android布局之GridLayout网格布局
- Android应用开发中使用GridView网格布局的代码示例
- 第16章、布局Layouts之GridLayout网格布局(从零开始学Android)
- Android的网格布局设计简单实例--GridView
- 【Android】UI出现前获知组件尺寸,改变布局