ViewDynamic

动态添加布局

LinearLayout添加
  • 父容器

    1
    2
    3
    4
    5
    6
    <LinearLayout
    android:id="@+id/ll_plan_one"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    </LinearLayout>
  • 子布局

    1
    2
    3
    View view1 = inflate.inflate(R.layout.layout_animation, null);
    View view2 = inflate.inflate(R.layout.ic_hpan_suger_press_y, null);
    View view3 = inflate.inflate(R.layout.ic_hpan_suger_press_y, null);
  • 添加进容器

    1
    2
    3
    llVertical.addView(view1);
    llVertical.addView(view2);
    llVertical.addView(view3);
  • 添加同一个子布局会报错

    1
    2
    llVertical.addView(view1);
    llVertical.addView(view1);

    ​ Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.


ViewDynamic
https://noteforme.github.io/2018/07/17/ViewDynamic/
Author
Jon
Posted on
July 17, 2018
Licensed under