【发布时间】:2012-10-04 13:48:21
【问题描述】:
我有一个主要的线性布局,其中包含动态生成的线性布局。我在 ACTION_DOWN 上为这些布局设置动画。但是,如果我尝试更改一种布局的边距(顶部或底部),它也会影响其他布局。如何在不影响其他布局的情况下更改一个布局边距。
任何帮助将不胜感激。
谢谢。
编辑
public View getLinearView() {
ChildLinearLayout linearLayout = new ChildLinearLayout(context);
LayoutParams layoutParams = new LayoutParams(500, 500);
linearLayout.setLayoutParams(layoutParams);
linearLayout.setBackgroundColor(Color.RED);
layoutParams.setMargins(20, 20, 20, 20);
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
TextView textView = new TextView(context);
textView.setText("Hello World");
linearLayout.addView(textView);
System.out.println("View Added");
views.add(linearLayout);
return linearLayout;
}
【问题讨论】:
-
尝试将这些布局与一些不变的(静态)布局对齐,而不是改变布局。
-
你确定没有在所有动态生成的
LinearLayouts中设置相同的LayoutParams,让它们共享布局属性吗? -
@Luksprog 我已经更新了我的问题。这就是我添加布局的方式。
标签: android android-linearlayout margin