【问题标题】:How to set a desired layout for an animating fragment?如何为动画片段设置所需的布局?
【发布时间】:2012-10-01 08:28:12
【问题描述】:

我有一个从右到左动画的片段。我想将其设置为距离屏幕左侧 100 个单位。这就是我到目前为止所做的。

    RelativeLayout tempLi;
    Display display = MyActivity.context.getWindowManager().getDefaultDisplay();
    final int width = display.getWidth();

   tempLi.setLayoutParams(new LayoutParams(width-100, LayoutParams.FILL_PARENT));

这行代码使布局距离右侧少了 100 个单位。我试着做 -width + 100 ,它没有用。 任何建议将不胜感激。 TIA

【问题讨论】:

  • 您是否尝试过为布局分配左边距?

标签: android animation layout fragment


【解决方案1】:

您可以按如下方式设置布局的左边距:

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layoutParams.setMargins(100, 0, 0, 0);
    tempLi.setLayoutParams(layoutParams);        

【讨论】:

  • 我收到一个错误,setMargins() 未定义为 ViewGroup.LayoutParams
  • 代码更新为使用RelativeLayout.LayoutParams。请检查。
  • 老兄,什么也没发生。它覆盖了整个屏幕。
猜你喜欢
  • 2012-01-09
  • 2018-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-27
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
相关资源
最近更新 更多