权重平等分布局And TableRow布局误区
16lz
2021-01-26
开头语:
本人最近在自学Android,虽然本人有2年Java Web的开发经验。但是发现Android的自学之路并不是那么平坦,我没有Android真机。但是有一个window phone的手机。开始想做一个通讯录。但是没有参考软件。这样一来我参考wp平台的通讯录去开发本软件,这其中遇到了一些关于sqlite、键盘布局等问题。本文说一说布局的权重问题吧
个人理解:
权重是一个在指定组件内等分该组件空间的一种手段。在android中的设置方式为android:layout_weight="X"
本人案例截图:
说明:
如上图我做的键盘排版每四个按照为一行。详细的布局为4个按钮在一个LinearLayout中。那么只要将按钮的权重都设置为1即可。
那么就会把父元素(LinearLayout)组件4等分。[因为这里有四个按钮。当然有2个按钮则2等分。我这么说我想大家应该都可以理解了吧]
部分代码解析:
<LinearLayout android:id="@string/l1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:orientation="horizontal" > <Button android:id="@+id/buttonjing" android:layout_width="match_parent" android:layout_height="50dip" android:layout_weight="1" android:text="@string/jing" /> <Button android:id="@+id/buttonA" android:layout_width="match_parent" android:layout_height="50dip" android:layout_weight="1" android:text="@string/A" /> <Button android:id="@+id/buttonB" android:layout_width="match_parent" android:layout_height="50dip" android:layout_weight="1" android:text="@string/B" /> <Button android:id="@+id/buttonC" android:layout_width="match_parent" android:layout_height="50dip" android:layout_weight="1" android:text="@string/C" /> </LinearLayout>
说明:
OK,上面代码为从#号到C按钮一行的排版。这一行的排版。可以看到4个btn的属性的权重都为1.其中width最好是设置上。
误区说明:
在尝试LinearLayout布局此界面之前我用过TableLayout和TableRow去搭配。虽然TableRow组件也可以用权重4等分。但是发现其高度无法调整。总是占用手机屏幕的半屏。再次说明一下。避免再犯!!
更多相关文章
- Android实现秒表计时器的程序设计
- 防止Android过快点击造成多次事件的三种方法
- Android界面UI开发中按钮Button的使用
- Android(安卓)实现按钮 跳转到某网页
- [Android(安卓)Studio]掌握Android(安卓)Studio的五种常见控件和
- Android:dkplayer非全屏时候显示返回按钮
- (4.2.6)【android开源组件】SwitchButton 开关按钮 的多种实现方式
- 【Android】利用安卓的数据接口、多媒体处理编写内存卡Mp3播放器
- Android切换按钮与沉浸式状态栏的实现