【问题标题】:How to get LinearLayout's children as a viewgroup?如何将 LinearLayout 的子项作为视图组?
【发布时间】:2016-08-15 21:49:54
【问题描述】:

我有一个LinearLayout,有 9 个静态孩子。我想让 2 个孩子(按顺序,例如 childAt(0)childAt(1))作为 ViewGroup 以应用动画。 我不想创建一个新的LinearLayout,因为我需要先从它的父母那里移除孩子,它实际上会移除孩子,我不这样做,因为我只想让这些孩子一起制作动画。

例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>

我想让孩子 2 和 3 成为ViewGroup

【问题讨论】:

  • 既然 LinearLayout 已经是一个视图组,有没有办法让孩子 2 和 3 作为视图组?

标签: android animation android-linearlayout viewgroup


【解决方案1】:

你的意思是ViewGroup.addView(View)

viewgroup.addView(lview.childAt(0))
viewgroup.addView(lview.childAt(1))

【讨论】:

  • 这行不通,因为您需要创建一个视图组。我不确定我们是否可以在 onLayout() 中合并 2 个孩子。 ViewGroup viewGroup = new ViewGroup() { @Override protected void onLayout(boolean b, int i, int i1, int i2, int i3) { // ? } }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多