在gridlayout的给定行/列中使用include标记

时间:2017-03-04 12:30:05

标签: android android-layout calendar android-gridlayout

我正在构建一个应该显示带有月和日的全年日历的布局。我已经构建了代表月和日的布局,但现在我无法在给定的x / y位置将其插入gridlayout,因为IDE显示flavorDimensions "flavor" productFlavors { flavor1 { dimension "flavor" applicationId "net.flavor1" versionName "2.0.1" versionCode 31 } flavor2{ dimension "flavor" applicationId "net.flavor2" versionName "1.0.1" versionCode 3 } } sourceSets { flavor1 { java.srcDirs = ['src/main/java/net.flavor1/Configuration.java'] } flavor2{ java.srcDirs = ['src/flavor2/Configuration.java'] } }

基本上,我想要实现的是:

enter image description here

这是我的文件

calendar_month.xml

Exception raised during rendering: <include /> can only be used inside of a ViewGroup (Details)

calendar_year.xml

<?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"
    android:paddingBottom="10dp"
    android:paddingTop="10dp">

    <TextView
        android:id="@+id/calendar_month_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_marginStart="10dp"
        android:layout_marginLeft="10dp"
        android:text="MONTH" />

    <!-- days header -->
    <LinearLayout
        android:id="@+id/calendar_header"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:weightSum="7">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="SUN"
            android:textColor="#222222" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="MON"
            android:textColor="#222222" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="TUE"
            android:textColor="#222222" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="WED"
            android:textColor="#222222" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="THU"
            android:textColor="#222222" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="FRI"
            android:textColor="#222222" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="SAT"
            android:textColor="#222222" />
    </LinearLayout>

    <!-- days view -->
    <GridView
        android:id="@+id/calendar_grid"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:verticalSpacing="3dp"
        android:numColumns="7" />
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

交换View FrameLayout或其他来自ViewGroup的视图,如下所示:

<FrameLayout android:layout_row="0"
    android:layout_column="0">
    <include
        android:id="@+id/calendar_month_1"
        layout="@layout/calendar_month_view" />
</FrameLayout>

请参阅documentation