Dynamically set width and height of TextView in Android

I am trying to set the width of the TextView dynamically using the setWidth(width) method.

 txtviewOne.setWidth(10); txtviewTwo.setWidth(10); 

But not success.

Please help me. How to set the dynamic width of the text.

+6
source share
3 answers
 TextView tv; ---------------------- tv=new TextView(this); // or tv=new TextView(R.id.textview1); LinearLayout.LayoutParams Params1 = new LinearLayout.LayoutParams(15,50); tv.setLayoutParams(Params1); 
+8
source

I call new TableRow() because parentView is parent TableRow . If your parent view is LinearLayout , replace it with new LinearLayout.LayoutParams .

 textView.setLayoutParams( new TableRow.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); 
+3
source

I experienced something similar in situations where there is a ScrollView in the parent hierarchy. No matter how I would change the layout inside, my commands were ignored. If so, try calling RequestLayout on the ScrollView or removing and re-adding the ScrollView child view.

0
source

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


All Articles