【问题标题】:How to move text fields or buttons or any content in a fragment in android?如何在android的片段中移动文本字段或按钮或任何内容?
【发布时间】:2016-12-27 16:17:58
【问题描述】:

我想知道如何在fragment 上移动任何内容,例如edittextbutton 等。

我搜索了很多,但我发现如何将fragment 从左到右或从右到左移动。我不想移动fragment,我想移动fragments 中的内容。 当我按下下一个button edittext 字段时,我想将它移到右侧,然后出现另一个字段。

所有这些都应该在fragment 上完成。在一个简单的activity 中,我使用animation 做到了这一点,但在fragment 中我做不到同样的效果。

【问题讨论】:

  • 为什么是粗体,为什么是斜体?
  • 你在和Ms.Word一起工作吗..很好,但我的眼睛@_@

标签: android android-fragments fragment


【解决方案1】:

您可以通过以下代码更改任何视图的父级:

要将视图从一个片段移动到另一个片段,首先将其从原始父级中删除:

ViewGroup parent = (ViewGroup) yourChildView.getParent();     

if (parent != null) {
    // detach the child from parent or you get an exception if you try
    // to add it to another one
    parent.removeView(yourChildView);
}

现在将它添加到所需的片段或视图中:

// you might have to update the layout parameters on your child
// for example if your child was attached to a RelativeLayout before
// and you add it to a LinearLayout now
// this seems very odd coming from iOS but iOS doesn't support layout
// management, so...
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(//required params);
yourChildView.setLayoutParams(params);

yourNewParent.addView(yourChildView);

【讨论】:

    【解决方案2】:

    动画也应该在片段内工作。使用对象动画器将视图组件从一个地方移动到另一个地方。例如

    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view,"translationX", 0, 750); // start , end position
    objectAnimator.setDuration(1000);
    objectAnimator.start();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 2018-06-24
      相关资源
      最近更新 更多