【问题标题】:Can't Able to add two FrameLayout Objects in LinearLayout programmatically无法以编程方式在 LinearLayout 中添加两个 FrameLayout 对象
【发布时间】:2014-10-29 00:20:24
【问题描述】:

在以编程方式在 LinearLayout 对象中添加两个 FrameLayout 对象时,在将第二个 FrameLayout 对象添加到 LinearLayout 对象时出现以下异常。谁能帮忙。

Java.Lang.IllegalStateException:指定的孩子已经有一个父母。您必须先在孩子的父母上调用 removeView()。

这里是代码

ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(
                               ViewGroup.LayoutParams.WrapContent, 
                               ViewGroup.LayoutParams.WrapContent);

MainView = new LinearLayout(_context);
MainView.LayoutParameters = new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MatchParent, 
                            ViewGroup.LayoutParams.MatchParent);

MainView.Orientation = Orientation.Vertical;
MainView.SetVerticalGravity(GravityFlags.Center);
MainView.SetHorizontalGravity(GravityFlags.Center);




_currentSwipableItemReflectionFrameLayout = _currentSwipableItemFrameLayout;
_currentSwipableItemReflectionFrameLayout.RotationX = 180;
_currentSwipableItemReflectionFrameLayout.Alpha = 0.3f;

MainView.AddView(_currentSwipableItemFrameLayout,param);
MainView.AddView(_currentSwipableItemReflectionFrameLayout,param);

AddView(MainView);

【问题讨论】:

    标签: android-layout xamarin.android


    【解决方案1】:

    例外说明了一切。您尝试使用AddView 添加的视图之一已作为子视图添加到视图层次结构中的某个位置。因此,您必须先将其从其父级中删除,然后再将其添加到其他位置。

    从您发布的代码来看,_currentSwipableItemFrameLayout_currentSwipableItemReflectionFrameLayout 中的一个或两个似乎已经有一个父级。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多