1

I have a FrameLayout in my application and in the xml file its width and height is set to wrap_content . then I want to change its dimensions programmatically like this :

FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
ViewGroup.LayoutParams previewParam = preview.getLayoutParams() ;
previewParam.height =(int) (height * 0.86);
previewParam.width = (int)(previewParam.height/ratio) ;
preview.setLayoutParams(previewParam) ;

When I do this the program exits when I start this activity, is the problem with wrap_content or not ?

Navid777
  • 3,591
  • 8
  • 41
  • 69

1 Answers1

2

I believe its because previewParam is null at that point. Try doing it like this:

FrameLayout preview = (FrameLayout) findViewById(R.id.abs__action_bar);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams((height/ratio),
         (int) (height * 0.86));
preview.setLayoutParams(params);
preview.requestLayout();
waqaslam
  • 67,549
  • 16
  • 165
  • 178