《android课表》之的表格界面的编写(button不随文本字数的变化而变化)

在尝试创建一个Android课表应用时,遇到了按钮大小随文本内容变化的问题。原本使用TableLayout和Button实现,但发现布局会因文本长度不同而失调。通过在RelativeLayout中结合weight属性,成功解决了这个问题,使得按钮大小保持一致。课表界面仍在开发中,布局调整是Android版的一大挑战。
摘要由CSDN通过智能技术生成

最近突然有想给自己写个课表的冲动,但是当想制作课表的界面时,第一步最遇到问题了。本来我想一周的课表按理想中那样显示文本。

其中有课程的颜色的都是按钮。。也就是说整个界面都布满了按钮。刚刚开始使用变表格布局的方式,用<TableLayout>嵌套<TableRow>然后<TableRow>中嵌套<Button>的方式来对界面编排。。其中每个TableRow和button的属性中都有android:layout_weight="1"来控制每行每列的比例都为1的比例来布满整个界面。。。但是调试出现的结果却让人很失望。。。。。因为这些按钮都会随文本的变化而变化。有些没课的地方被压缩的没有了。

就这样我就一直纠结这个问题,上网查了很久都没找到任何解决方案。然后一天在群里面听见别人在讨论RelativeLayout与weight进行搭配对界面的排版有神效。。然后我就想可不可以用<RelativeLayout>来嵌套<TableRow>其他不变。。。。之后一调试竟然成功了。。下面是代码。

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

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/linear"
        android:layout_width="fill_parent"
        android:layout_height="86dp"
        android:background="@drawable/week_bg1"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/text_top"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#000000"
            android:textSize="25dp" />
    </LinearLayout>

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/linear"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/relative1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <TableRow
                android:id="@+id/row1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/but1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#FFF0F0"
                    android:text="" />

                <Button
                    android:id="@+id/but2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#FFF000"
                    android:text="" />

                <Button
                    android:id="@+id/but3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#FFF0F0"
                    android:text="" />

                <Button
                    android:id="@+id/but4"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#F0F0FF"
                    android:text="" />

                <Button
                    android:id="@+id/but5"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#0FFFF0"
                    android:text="" />

                <Button
                    android:id="@+id/but6"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#FFF000"
                    android:text="" />

                <Button
                    android:id="@+id/but7"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#0F0FFF"
                    android:text="" />

                <Button
                    android:id="@+id/but8"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#FFF000"
                    android:text="" />
            </TableRow&g
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值