0

我希望一个图像左对齐,另一个图像右对齐,但目前这两个图像只是在中间相遇。

有任何想法吗?

    View v = inflater.inflate(R.layout.fragment_hello_moon, parent, false);

    TableLayout tl = (TableLayout)v.findViewById(R.id.l1);
    TableRow tr = new TableRow(getActivity());
    tr.setPadding(50, 0, 50, 0);

    TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.RIGHT;

    ImageView imageL = new ImageView(getActivity());
    imageL.setImageResource(R.drawable.bell_dl_256);

    ImageView imageR = new ImageView(getActivity());
    imageR.setImageResource(R.drawable.bell_dr_256);
    imageR.setLayoutParams(params);

    tr.addView(imageL);
    tr.addView(imageR);
    tl.addView(tr);

    return v;
4

1 回答 1

1

如果我是你,我会使用 RelativeLayout。只有当两个 ImageView 足够做你想做的事情时,你才能使用方向属性为水平的 LinearLayout。最后一个建议,你可以在 xml 布局中做到这一点。

于 2013-10-21T14:54:07.370 回答