最近突然有想给自己写个课表的冲动,但是当想制作课表的界面时,第一步最遇到问题了。本来我想一周的课表按理想中那样显示文本。
其中有课程的颜色的都是按钮。。也就是说整个界面都布满了按钮。刚刚开始使用变表格布局的方式,用<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