0
private void generateView() {
    for (int i = 0; i < 10; i++) {
        mview = new LinearLayout(getActivity());
        mview.setBackgroundResource(R.color.grayColor);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(10, 40);
        layoutParams.setMargins(5, 0, 5, 0);
        mview.setLayoutParams(layoutParams);
        lnLinearlayout.addView(mview);
    }
}

Using this code I am able to display views like this:

||||||||||

I want to increase the height of the views at position 4 and 8. I am trying to do so using:

lnLinearlayout.getChildAt(4).setMinimumHeight(20) lnLinearlayout.getChildAt(8).setMinimumHeight(20)

but there is no change in the views. Can anyone please suggest how to increase the height of a particular view?

TofferJ
  • 4,678
  • 1
  • 37
  • 49
Adevelopment
  • 265
  • 3
  • 15

2 Answers2

1

Use below code..

 LinearLayout.LayoutParams layoutParams=(LinearLayout.LayoutParams)lnLinearlayout.getChildAt(4).getLayoutParams();
    layoutParams.height=20;
    layoutParams=(LinearLayout.LayoutParams)lnLinearlayout.getChildAt(8).getLayoutParams();
    layoutParams.height=20;
Mayank Pandya
  • 265
  • 3
  • 14
  • it becoming small but not bigger when i put 20 then i have put 100 then same hight @Mayank Pandya – Adevelopment Jul 26 '17 at 13:00
  • Have you removed lnLinearlayout.getChildAt(4).setMinimumHeight(20) this line? or Checked the height of LinearLayout in which you put all these children ? – Mayank Pandya Jul 27 '17 at 04:04
0

try this

lnLinearlayout.getChildAt(4).setLayoutParams(new LinearLayout.LayoutParams(10, 200));
Anmol317
  • 1,356
  • 1
  • 14
  • 31