How to set viewing weight?

I am trying to get views inside LinearLayout to fill the width. I tried installing it using LayoutParams, but it gave me an error:

My code is:

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); 

Error:

Constructor ActionBar.LayoutParams (int, int, float) not defined

+4
source share
3 answers

Just what the error says, the ActionBarLayoutParams constructor accepts a float. You need one of the available gravity engraving constants

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

 import android.widget.LinearLayout.LayoutParams 

ActionBar.LayoutParams

LinearLayout.LayoutParams

+6
source

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

or change the 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)); 
+5
source

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

+1
source

Source: https://habr.com/ru/post/1482238/


All Articles