这类似于我的 previous question但它不适用于 Kindle Fire (2.3.4)。
我使用 FragmentTransaction 将 Fragment 添加到 FrameLayout 中。我想动态更改 fragment 使用的 RelativeLayout 的边距。
但是,Kindle Fire 上的边距不会随 FrameLayout.layoutParams 改变。但是,这适用于 3.2.1。我也尝试过使用 setMargins() 但它没有用。
有谁知道如何动态更改 Kindle Fire 上的页边距?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.infocard, container, false);
RelativeLayout infoLayout = (RelativeLayout) view.findViewById(R.id.info);
infoLayout.setOnClickListener(new EmptyClickListener());
final int width = 250;
final int height = 270;
int leftMargin = 0;
int topMargin = 0;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, height);
if (x - width < 0) {
leftMargin = 0;
} else {
leftMargin = x - width + 40;
}
if (y >= 400 && y <= 480) {
topMargin = 160;
}
params.leftMargin = leftMargin;
params.topMargin = topMargin;
//params.setMargins(leftMargin, topMargin, 0, 0); //this didnt work either
infoLayout.setLayoutParams(params);
TextView titleView = (TextView) view.findViewById(R.id.titleCard);
titleView.setText(title);
return view;
}
最佳答案
好的,我可以通过将我的 infoLayout 包装在另一个 RelativeLayout 中来解决这个问题,现在它可以完美地工作了
关于android - 在 RelativeLayout 上设置边距在 Kindle Fire 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9813894/