0

I've been following [this] answer to try to correct the heights of some image buttons in a scroll view, since I can't use linear layout weights. This is the code I've come up with:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_plant_list);
    final ImageButton buttonPlant1= (ImageView) findViewById(R.id.buttonPlant1);
    final ScrollView scrollViewPlant = (ScrollView) findViewById(R.id.scrollViewPlant);
    scrollViewPlant.post(new Runnable() {
        @Override
        public void run() {
            int scrollPlantHeight = scrollViewPlant.getHeight();
            LinearLayout.LayoutParams layoutParams  = new    
                 LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, scrollPlantHeight / 3.69);
            buttonPlant1.setLayoutParams(layoutParams);
        }
    });
}

I keep getting an alert in my code telling me that I need to import a class before the "LayoutParams.MATCH_PARENT."

When I import a class (I'm not even sure which one to import, but all I've tried is LinearLayout.LayoutParams), I get another alert telling me that it "Cannot resolve constructor 'LayoutParams(int, double)'" at the LayoutParams.MATCH_PARENT.

What class should I import? If any? Or is there something else I'm missing?

Community
  • 1
  • 1

1 Answers1

0

LayoutParams Class doesn't have constructor with (int, double).
Try casting the second parameter to integer.

LinearLayout.LayoutParams layoutParams  = new    
                 LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int)(scrollPlantHeight / 3.69));
Suhyeon Lee
  • 569
  • 4
  • 18
  • @AmericanRaisin Exactly which code requires importing? If it's [LayoutParams.MATCH_PARENT] itself, then import LinearLayout.LayoutParams. – Suhyeon Lee Mar 11 '16 at 03:28
  • Thanks! I tried that and everything works perfectly. –  Mar 11 '16 at 16:08