如何以文本没有离开屏幕的方式创建TableLayout

时间:2014-05-22 21:02:38

标签: java android tablelayout android-tablelayout

我解析了网站,现在尝试将数据放入TableLayout。但我无法正确建立表格。在纵向方向上,结果是可以接受的,在景观中是可怕的。而不是屏幕上的8列,它只显示3。

这是我想要实现的目标 - Schedule Online

我的activity_main.xml部分横向广告。

您能否告诉我如何才能获得正确的时间表?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="sm.play.sportlife.ua.MainActivity"
    tools:ignore="MergeRootFrame" >

    <TableLayout
        android:id="@+id/tableLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1, 2, 3, 4, 5, 6, 7" >

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/shape_rec" >

            <TextView
                android:id="@+id/textView0"
                android:layout_width="70dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal"
                android:text="Time"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal"
                android:text="Monday"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal"
                android:text="Tuesday"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal"
                android:text="Wednesday"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal"
                android:text="Thursday"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal"
                android:text="Friday"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal"
                android:text="Saturday"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView7"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal"
                android:text="Sunday"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/shape_rec" >

            <TextView
                android:id="@+id/textViewDate0"
                android:layout_width="70dp"
                android:layout_height="match_parent"
                android:gravity="center_horizontal"
                android:paddingLeft="5dp"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textViewDate1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/textViewDate2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/textViewDate3"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/textViewDate4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/textViewDate5"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/textViewDate6"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/textViewDate7"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec"
                android:gravity="center_horizontal" />
        </TableRow>
    </TableLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tableLayout" >

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1, 2, 3, 4, 5, 6, 7" >

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/shape_rec" >

                <TextView
                    android:id="@+id/R1C1"
                    android:layout_width="70dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_horizontal|center_vertical" />

                <TextView
                    android:id="@+id/R1C2"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R1C3"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R1C4"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R1C5"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R1C6"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R1C7"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R1C8"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec" >

                <TextView
                    android:id="@+id/R2C1"
                    android:layout_width="70dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_horizontal|center_vertical" />

                <TextView
                    android:id="@+id/R2C2"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R2C3"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R2C4"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R2C5"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R2C6"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R2C7"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R2C8"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/shape_rec" >

                <TextView
                    android:id="@+id/R3C1"
                    android:layout_width="70dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_horizontal|center_vertical" />

                <TextView
                    android:id="@+id/R3C2"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R3C3"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R3C4"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R3C5"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R3C6"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R3C7"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    android:id="@+id/R3C8"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/shape_rec"
                    android:paddingLeft="5dp"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
            </TableRow>


        </TableLayout>
    </ScrollView>

</RelativeLayout>

提前致谢!!

0 个答案:

没有答案