Android:使用TableLayout创建Weekview

时间:2018-07-25 18:48:14

标签: android android-studio android-gridview android-tablelayout android-gridlayout

我一直试图在Google Play商店中基于时间表创建应用程序。开发人员创建了一个网格来处理一周内的时间表。我正在尝试完成导航抽屉活动中的一个片段。

As you can see in this screenshot, it is currently Wednesday, at 1:23 PM and the passed time (Sunday, Monday, Tuesday, and some of Wednesday) has passed. The user can also click on a cell to add a lesson that corresponds with the hour and day of the week. How can I achieve something similar to this?

除非有人知道解决方案,否则我主要是在寻找方向。我什至不确定是否可以使用TableLayout做到这一点。如何使用TableLayout网格(或其他类型的网格)实现星期几?我也不明白分钟如何突出时间的逻辑。我已经完成了该应用程序的全部工作,但是我不知道该部分的解决方案。

这是fragment_week.xml (简称为节省空间)

.then((response) => {
      dispatch(addMarkersSuccess(response));
    }).catch((error) => {
      dispatch(addMarkersFailure(error));
    });

这是WeekFragment.java

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".WeekFragment">

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:stretchColumns="*">

        <TableRow
            android:id="@+id/titleRow"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center"
            android:orientation="horizontal"
            android:padding="2dp">

            <TextView
                android:layout_width="10dp"
                android:text="" />

            <TextView
                android:layout_width="20dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="Sun"
                android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                android:textSize="15sp"
                tools:targetApi="lollipop" />

            <TextView
                android:layout_width="20dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text=" Mon"
                android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                android:textSize="15sp"
                tools:targetApi="lollipop" />

            <TextView
                android:layout_width="20dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text=" Tue"
                android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                android:textSize="15sp"
                tools:targetApi="lollipop" />

            <TextView
                android:layout_width="20dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text=" Wed"
                android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                android:textSize="15sp"
                tools:targetApi="lollipop" />

            <TextView
                android:layout_width="20dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text=" Thu"
                android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                android:textSize="15sp"
                tools:targetApi="lollipop" />

            <TextView
                android:layout_width="20dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text=" Fri"
                android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                android:textSize="15sp"
                tools:targetApi="lollipop" />

            <TextView
                android:layout_width="20dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text=" Sat"
                android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                android:textSize="15sp"
                tools:targetApi="lollipop" />
        </TableRow>

    </TableLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="28dp"
        android:scrollbars="none">

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


            <TableRow
                android:id="@+id/sevenAM"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_shape">

                <TextView
                    android:layout_width="45dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/cell_shape"
                    android:gravity="end"
                    android:paddingRight="8dp"
                    android:paddingTop="2dp"
                    android:text="7:00\nAM"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textSize="11sp"
                    tools:targetApi="lollipop" />

                <ImageView
                    android:layout_height="45dp"
                    android:layout_width="1dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:layout_width="1dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:layout_width="1dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:layout_width="1dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:layout_width="1dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:layout_width="1dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:layout_width="1dp"
                    android:background="@drawable/cell_shape" />
            </TableRow>


            <TableRow
                android:id="@+id/eightAM"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_shape">

                <TextView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape"
                    android:gravity="end"
                    android:paddingRight="8dp"
                    android:paddingTop="2dp"
                    android:text="8:00\nAM"
                    android:textAlignment="textEnd"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textSize="11sp"
                    tools:targetApi="lollipop" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />
            </TableRow>

            <TableRow
                android:id="@+id/nineAM"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_shape">

                <TextView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape"
                    android:gravity="end"
                    android:paddingRight="8dp"
                    android:paddingTop="2dp"
                    android:text="9:00\nAM"
                    android:textAlignment="textEnd"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textSize="11sp"
                    tools:targetApi="lollipop" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />
            </TableRow>

            <TableRow
                android:id="@+id/tenAM"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_shape">

                <TextView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape"
                    android:gravity="end"
                    android:paddingRight="8dp"
                    android:paddingTop="2dp"
                    android:text="10:00\nAM"
                    android:textAlignment="textEnd"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textSize="11sp"
                    tools:targetApi="lollipop" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />
            </TableRow>

            <TableRow
                android:id="@+id/elevenAM"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_shape">

                <TextView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape"
                    android:gravity="end"
                    android:paddingRight="8dp"
                    android:paddingTop="2dp"
                    android:text="11:00\nAM"
                    android:textAlignment="textEnd"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textSize="11sp"
                    tools:targetApi="lollipop" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />
            </TableRow>


            <TableRow
                android:id="@+id/twelvePM"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_shape">

                <TextView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape"
                    android:gravity="end"
                    android:paddingRight="8dp"
                    android:paddingTop="2dp"
                    android:text="12:00\nPM"
                    android:textAlignment="textEnd"
                    android:textAppearance="@android:style/TextAppearance.Material.Subhead"
                    android:textSize="11sp"
                    tools:targetApi="lollipop" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />

                <ImageView
                    android:layout_height="45dp"
                    android:background="@drawable/cell_shape" />
            </TableRow>
        </TableLayout>
    </ScrollView>
</FrameLayout>

0 个答案:

没有答案