1

これは私の前の質問に似ていますが、Kindle Fire(2.3.4)では機能しませんでした。
FragmentTransactionを使用してFragmentをFrameLayoutに追加しました。フラグメントで使用されるRelativeLayoutのマージンを動的に変更したいと思います。

ただし、KindleFireの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 に答える