0

I need to programmatically align an ImageView to the bottom of a LinearLayout.

I, of course, already tried to add the ImageView as a child of the LinearLayout, but the image get shrinked (cause the LinearLayout is smaller than the image), and I need the image not be resized, only bottom-aligned.

I also tried this :

    RelativeLayout main_layout = (RelativeLayout) view.findViewById(R.id.main_layout);
    LinearLayout line_0_layout = (LinearLayout) view.findViewById(R.id.line_0_layout);

    ImageView horse_img = new ImageView(getActivity());
    horse_img.setImageResource(R.drawable.horse);

    RelativeLayout.LayoutParams layout_params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layout_params.addRule(RelativeLayout.ALIGN_BOTTOM, line_0_layout.getId());

    horse_img.setLayoutParams(layout_params);
    main_layout.addView(horse_img);

but it doesn't work : the image is added to the view but not aligned to the LinearLayout.

It seems simple question, but it's not.

Thanks in advance for your help.

4

1 回答 1

0
layout_params.addRule(RelativeLayout.BELOW, line_0_layout.getId());
于 2013-10-02T08:21:27.480 回答