I've created a TextView within a LinearLayout programmatically:
LinearLayout filmTitleContainer = new LinearLayout(ctx);
TextView filmName = new TextView(ctx);
filmName.setBackgroundColor(Color.rgb(Color.YELLOW));
filmName.setText(this.screeningTime+" "+this.name);
The text view is shrunk:
How do I set the text to the occupy the full width of the screen? When I use the XML layout file, I'd set android:layout_width="match_parent"
. What's the equivalent Java code?
Use LayoutParams
for both the view and its container:
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f);
filmTitleContainer.setLayoutParams(params);
filmName.setLayoutParams(params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With