首页 > 解决方案 > 如何以编程方式在布局点击位置添加视图?

问题描述

如何在点击布局的地方创建视图?图片中是这样的:

屏幕

该表是根据每天的相对布局构建的。

   <ScrollView
    android:id="@+id/calendarScrollView"
    ...... >
    <RelativeLayout
        android:id="@+id/calendarRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="0dp" >

    <LinearLayout
        android:id="@+id/calendarSplitterRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        android:padding="0dp" >
        .......
        <RelativeLayout
            android:id="@+id/mondayRelativeLayout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2" >

            <include layout="@layout/calendar_zebra" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/tuesdayRelativeLayout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2" >

            <include layout="@layout/calendar_zebra" />

            <com.example.admin.nuschedule.view.LessonEventView
                android:layout_width="match_parent"
                android:layout_height="60dp"
                app:lessonName="CSCI 321"
                app:lessonRoom="7.257"/>

        </RelativeLayout>
           .......

    </LinearLayout>

    </RelativeLayout>
</ScrollView>

实际上,我想我应该听一下 relativelayout 点击并以编程方式添加新视图

现在任何人都可以如何在代码中实现它吗?

标签: javaandroidandroid-layoutandroid-studioandroid-custom-view

解决方案


推荐阅读