4

I'm trying to get the views inside a LinearLayout to fill the width. I have tried setting it by using LayoutParams, but it gave me an error:

My code:

EditText et = new EditText(v.getContext());
                    et.setHint("asset ");
                    et.setTextSize(12);
                    et.setLayoutParams(new LayoutParams(
                            LayoutParams.WRAP_CONTENT,
                            LayoutParams.WRAP_CONTENT, 0.25f));
                    et.setPadding(0, 15, 0, 10);

The error:

The constructor ActionBar.LayoutParams(int, int, float) is undefined

double-beep
  • 5,031
  • 17
  • 33
  • 41
kyokotsu
  • 145
  • 1
  • 3
  • 14

3 Answers3

6

Just what the error says, no ActionBarLayoutParams constructor takes a float. You need one of the available graivty constants for the gravity

But it looks like you are importing the wrong LayoutParams. If this is for a LinearLayout and not ActionBar then you need to be importing LinearLayout.LayoutParams

import android.widget.LinearLayout.LayoutParams

ActionBar.LayoutParams

LinearLayout.LayoutParams

Melquiades
  • 8,496
  • 1
  • 31
  • 46
codeMagic
  • 44,549
  • 13
  • 77
  • 93
5

change your import to use LinearLayout.LayoutParams not ActionBar.LayoutParams

or change code

et.setLayoutParams(new LayoutParams(
     LayoutParams.WRAP_CONTENT,
     LayoutParams.WRAP_CONTENT, 0.25f));

to

et.setLayoutParams(new LinearLayout.LayoutParams(
     LinearLayout.LayoutParams.WRAP_CONTENT,
     LinearLayout.LayoutParams.WRAP_CONTENT, 0.25f));
petey
  • 16,914
  • 6
  • 65
  • 97
1

Since you are using LinearLayout, I guess you should call LinearLayout.LayoutParams.

Volker E.
  • 5,911
  • 11
  • 47
  • 64
jbihan
  • 3,053
  • 2
  • 24
  • 34