线性布局和表格布局的嵌套使用

编写计算器的页面布局,前面几行很简单,用表格布局,后面的=号不知道怎么把一个按钮跨两行(希望知道的大神帮我解答一下),就用了线性布局,在写线性布局的时候,写好了表格运行效果可以,可再写好下面两行的时 候,上面的就不见了,就开始网上找线性布局的属性,发现漏了android:layout_weight=”4” 这个,layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空间。可是我设置的LinearLayout的大小是android:layout_width=”fill_parent”, android:layout_height=”match_parent” 这样,不应该占满全屏啊o(︶︿︶)o,希望知道的帮我解答一下 、最后加了一句android:layout_weight=”4” 才得到我想要的效果 最后的效果如下


代码如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_marginTop="10dp"
        android:layout_height="match_parent"
        android:layout_weight="4" >

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:shrinkColumns="3" >

            <EditText
                android:editable="false"
                android:id="@+id/textView1"
                android:layout_width="100dp"
                android:layout_height="70dp"
                android:layout_margin="10dp"
                android:background="@drawable/write_bg"
                android:gravity="right|center_vertical"
                android:paddingBottom="10dp"
                android:paddingRight="10dp"
                android:textSize="20sp" />
            <!-- 第一行 -->

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:gravity="center_horizontal"
                android:stretchColumns="*" >

                <Button
                    android:id="@+id/button1"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:background="@drawable/color_clect"
                    android:gravity="bottom|right"
                    android:paddingBottom="10dp"
                    android:paddingRight="10dp"
                    android:text="@string/bt1"
                    android:textSize="20sp" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_marginLeft="10dp"
                    android:background="@drawable/color_clect"
                    android:gravity="bottom|right"
                    android
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值