1

这类似于我之前的问题,但它不适用于 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;
    }
4

1 回答 1

3

好的,我可以通过将我的 infoLayout 包装在另一个 RelativeLayout 中来解决这个问题,现在它可以完美地工作了

于 2012-03-22T18:40:57.977 回答