1.概述
android开发当中有可能会碰到以下这种情况,某个页面,内容不确定,根据用户需求增加或减少相应控件数。这种情况一般发生在编辑类页面当中,比如你的应用包含用户发帖功能,其内容组织结构和多少是可变的。
本文实现了一个动态添加和删除控件的简单例子!先上截图:
2.代码实现
(1)布局文件activity_main.xml
<RelativeLayout 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"
android:background="@android:color/darker_gray"
tools:context=".MainActivity" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer=